我有一个小样本代码:
主要类别:
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));
}
}
fxml地址:
<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内容就会消失(如果底部有第二个滚动条,则内容不会消失)。在向下滚动之后,它又出现了,所以它不是一个可怕的bug,而是一个令人讨厌的bug。
有人对这个错误有什么解释或者解决方法吗?
谢谢
编辑:
以下是sunflame要求的屏幕截图:
我使用的是Java8,JFX11,我的操作系统是Ubuntu18.04.5LTS(BionicBeaver)
暂无答案!
目前还没有任何答案,快来回答吧!