2023-02-16 372
在使用TreeTableView工作时,我意识到,当您向下滚动桌子并双击最后一个展开/折叠箭头时,所有项目都会消失.但是,当您再次滚动时,所有项目都重新出现.当然,当您有足够的项目时,这会发生这种情况.垂直ScrollBar处于活动状态.
有人以前经历过这个问题吗?这是一个已知问题吗?
简单示例:
import java.util.Arrays;
import java.util.List;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.layout.StackPane;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
public class App extends Application {
@Override
public void start(Stage stage) {
TreeTableView<List<String>> table = new TreeTableView<>();
table.setMaxHeight(250);
TreeTableColumn<List<String>, String> colCity = new TreeTableColumn<>("City");
TreeTableColumn<List<String>, String> colCountry = new TreeTableColumn<>("Country");
colCity.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().getValue().get(0)));
colCountry.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().getValue().get(1)));
table.getColumns().setAll(colCity, colCountry);
TreeItem<List<String>> root = new TreeItem<>(Arrays.asList("Root", ""));
root.setExpanded(true);
for (int i = 0; i < 10; i++) {
TreeItem<List<String>> item = new TreeItem<>(List.of("London", "UK"));
item.getChildren().add(new TreeItem<>(List.of("New York", "US")));
item.setExpanded(true);
root.getChildren().add(item);
}
table.setRoot(root);
Scene scene = new Scene(new StackPane(table));
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
我已经在:
上测试了此代码
由于Javafx 16解决了此问题.但是,这是旧javafx版本的 hacky 解决方案.
它通过将听众添加到expandedItemCountProperty()中来强制TreeTableView在需要时刷新:
table.expandedItemCountProperty().addListener(e -> {
VirtualFlow<?> virtualFlow = (VirtualFlow<?>) table.lookup(".virtual-flow");
if (virtualFlow != null && virtualFlow.getFirstVisibleCell() != null) {
int firstVisibleIndex = virtualFlow.getFirstVisibleCell().getIndex();
int visibleCells = virtualFlow.getLastVisibleCell().getIndex() - firstVisibleIndex;
if (firstVisibleIndex > visibleCells) {
table.refresh();
}
}
});
注意:使用问题中的示例进行了测试.
以上所述是小编给大家介绍的滚动滚动和双击最后一个扩展/倒塌箭头时,TreetableView项目消失了,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对77isp云服务器技术网的支持!
原文链接:https://77isp.com/post/33960.html
=========================================
https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。
数据库技术 2022-03-28
网站技术 2022-11-26
网站技术 2023-01-07
网站技术 2022-11-17
Windows相关 2022-02-23
网站技术 2023-01-14
Windows相关 2022-02-16
Windows相关 2022-02-16
Linux相关 2022-02-27
数据库技术 2022-02-20
抠敌 2023年10月23日
嚼餐 2023年10月23日
男忌 2023年10月22日
瓮仆 2023年10月22日
簿偌 2023年10月22日
扫码二维码
获取最新动态