java - 动态添加行时 TreeTableView 内容消失
问题描述
我有这个小示例代码:
主类:
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class Main extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage stage) throws IOException {
stage.setTitle("Tree Table View Samples");
FXMLLoader loader = new FXMLLoader();
Parent sceneRoot = loader.load(getClass().getResource("sample.fxml"));
Controller controller = new Controller();
loader.setController(controller);
final Scene scene = new Scene(sceneRoot, 450, 400);
stage.setScene(scene);
stage.show();
}
}
控制器:
public class Controller {
@FXML private Button btnAdd;
@FXML private Button btnDelete;
@FXML private TreeTableView<String> treeTableView;
@FXML private TreeTableColumn<String, String> columnC1;
public void initialize() {
final TreeItem<String> childNode1 = new TreeItem<>("Child Node 1");
final TreeItem<String> childNode2 = new TreeItem<>("Child Node 2");
final TreeItem<String> childNode3 = new TreeItem<>("Child Node 3");
final TreeItem<String> root = new TreeItem<>("Root node");
root.setExpanded(true);
root.getChildren().setAll(childNode1, childNode2, childNode3);
columnC1.setCellValueFactory((TreeTableColumn.CellDataFeatures<String, String> p) ->
new ReadOnlyStringWrapper(p.getValue().getValue()));
treeTableView.setRoot(root);
treeTableView.setShowRoot(true);
btnAdd.setOnAction(actionEvent -> root.getChildren().add(new TreeItem<>("Another Child")));
btnDelete.setOnAction(actionEvent -> root.getChildren().remove(root.getChildren().size()-1));
}
}
文件格式:
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="450.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<center>
<TreeTableView fx:id="treeTableView" prefHeight="100.0" prefWidth="430.0" BorderPane.alignment="CENTER">
<columns>
<TreeTableColumn fx:id="columnC1" prefWidth="430.0" text="C1" />
</columns>
</TreeTableView>
</center>
<bottom>
<HBox prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<Button fx:id="btnAdd" mnemonicParsing="false" prefHeight="35.0" prefWidth="113.0" text="Add" />
<Button fx:id="btnDelete" mnemonicParsing="false" prefHeight="35.0" prefWidth="95.0" text="Delete" />
</children>
</HBox>
</bottom>
我可以添加或删除行,这很好用。但是一旦右侧的滚动条出现并添加/删除行,而滚动条不在底部,TreeTableView 内容就会消失(如果底部有第二个滚动条,则内容不会消失)。向下滚动后它再次出现,所以这不是一个可怕的错误,而是一个烦人的错误。
有没有人解释这个错误甚至解决方案?
谢谢
编辑:
我正在使用 java 8、jfx 11 我的操作系统是 Ubuntu 18.04.5 LTS (Bionic Beaver)
解决方案
推荐阅读
- sql - 通过行聚合和新列创建转换表
- jsp - HTTP 状态 500 - 处理 JSP 页面时发生异常 //在获取值时
- php - 函数返回后在php中重置全局变量
- python - postgresql 更新功能耗时太长
- android - 如何在片段上绘制加密货币的指数移动平均数据?
- sql - 如何旋转然后计算数据?
- android - 如何解决 rxjava 异常?以下是来自 firebase crashanalytics 的日志
- firebase - 检测应用程序被杀死并清理 Firestore。Flutter 制作的语音聊天应用
- node.js - 清除node js应用中的mobx store-redis信息
- android - Android registerForActivityResult 拍照不会返回全尺寸照片