滚动时JavaFX TreeTableView行已消失

时间:2013-08-28 17:41:57

标签: java javafx-8

我一直在试验TreeTableView中的JDK 8。在我的程序启动并运行后,我注意到一个问题,当我滚动时,行将被消隐。我已尝试过重置单元格的可见性,更新时的所有内容,希望在更新时重绘,甚至重置列的可见性。这是一个我编写的测试applet,显示当你滚动树表视图时,行被消隐了,但对于表视图,情况并非如此。

public class TableViewTest extends Application{

private TreeTableView treeTable = new TreeTableView();
private TableView regularTable = new TableView();

 public static void main(String[] args) {
        launch(args);
    }

@Override
public void start(Stage stage) throws Exception {

    final ObservableList<Person> data = FXCollections.observableArrayList(
            new Person("Jacob", "Smith", "jacob.smith@example.com"),
            new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
            new Person("Ethan", "Williams", "ethan.williams@example.com"),
            new Person("Emma", "Jones", "emma.jones@example.com"),
            new Person("Michael", "Brown", "michael.brown@example.com"),
            new Person("Jacob", "Smith", "jacob.smith@example.com"),
            new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
            new Person("Ethan", "Williams", "ethan.williams@example.com"),
            new Person("Emma", "Jones", "emma.jones@example.com"),
            new Person("Michael", "Brown", "michael.brown@example.com"),
            new Person("Jacob", "Smith", "jacob.smith@example.com"),
            new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
            new Person("Ethan", "Williams", "ethan.williams@example.com"),
            new Person("Emma", "Jones", "emma.jones@example.com"),
            new Person("Michael", "Brown", "michael.brown@example.com"),
            new Person("Jacob", "Smith", "jacob.smith@example.com"),
            new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
            new Person("Ethan", "Williams", "ethan.williams@example.com"),
            new Person("Emma", "Jones", "emma.jones@example.com"),
            new Person("Michael", "Brown", "michael.brown@example.com"),
            new Person("Jacob", "Smith", "jacob.smith@example.com"),
            new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
            new Person("Ethan", "Williams", "ethan.williams@example.com"),
            new Person("Emma", "Jones", "emma.jones@example.com"),
            new Person("Michael", "Brown", "michael.brown@example.com"),
            new Person("Jacob", "Smith", "jacob.smith@example.com"),
            new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
            new Person("Ethan", "Williams", "ethan.williams@example.com"),
            new Person("Emma", "Jones", "emma.jones@example.com"),
            new Person("Michael", "Brown", "michael.brown@example.com"),
            new Person("Jacob", "Smith", "jacob.smith@example.com"),
            new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
            new Person("Ethan", "Williams", "ethan.williams@example.com"),
            new Person("Emma", "Jones", "emma.jones@example.com"),
            new Person("Michael", "Brown", "michael.brown@example.com"),
            new Person("Jacob", "Smith", "jacob.smith@example.com"),
            new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
            new Person("Ethan", "Williams", "ethan.williams@example.com"),
            new Person("Emma", "Jones", "emma.jones@example.com"),
            new Person("Michael", "Brown", "michael.brown@example.com")
        );


    // REGULAR TABLE -------------------------------------------------------------------------
    Scene tableScene = new Scene(new Group());
    Stage tableStage = new Stage();
    tableStage.setTitle("Table View Sample");
    tableStage.setWidth(300);
    tableStage.setHeight(500);

    tableStage.show();
    regularTable.getItems().addAll(data);

    regularTable.setEditable(true);

    TableColumn regularFirstNameCol = new TableColumn("First Name");
    TableColumn regularLastNameCol = new TableColumn("Last Name");
    TableColumn regularEmailCol = new TableColumn("Email");

    regularFirstNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));
    regularLastNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("lastName"));
    regularEmailCol.setCellValueFactory(new PropertyValueFactory<Person, String>("email"));

    regularTable.getColumns().addAll(regularFirstNameCol, regularLastNameCol, regularEmailCol);

    final VBox vbox1 = new VBox();
    vbox1.setSpacing(5);
    vbox1.setPadding(new Insets(10, 0, 0, 10));
    vbox1.getChildren().addAll(regularTable);

    ((Group) tableScene.getRoot()).getChildren().addAll(vbox1);

    tableStage.setScene(tableScene);

    // TREE TABLE ----------------------------------------------------------------------------------------------------------------------
    Scene scene = new Scene(new Group());
    stage.setTitle("Tree Table Sample");
    stage.setWidth(300);
    stage.setHeight(500);

    final Label label = new Label("Address Book");
    label.setFont(new Font("Arial", 20));

    treeTable.setEditable(true);

    TreeTableColumn firstNameCol = new TreeTableColumn("First Name");
    TreeTableColumn lastNameCol = new TreeTableColumn("Last Name");
    TreeTableColumn emailCol = new TreeTableColumn("Email");

    treeTable.getColumns().addAll(firstNameCol, lastNameCol, emailCol);

    final VBox vbox = new VBox();
    vbox.setSpacing(5);
    vbox.setPadding(new Insets(10, 0, 0, 10));
    vbox.getChildren().addAll(label, treeTable);

    ((Group) scene.getRoot()).getChildren().addAll(vbox);

    stage.setScene(scene);

    firstNameCol.setCellValueFactory(new TreeItemPropertyValueFactory<Person,String>("firstName"));
    lastNameCol.setCellValueFactory(new TreeItemPropertyValueFactory<Person,String>("lastName"));
    emailCol.setCellValueFactory(new TreeItemPropertyValueFactory<Person,String>("email"));

    TreeItem<Person> root = new TreeItem<Person>(new Person("TEST", "TEST", "TEST"));

    treeTable.setRoot(root);
    treeTable.setShowRoot(true);
    root.setExpanded(true);

    for (Person person : data){
        TreeItem<Person> p = new TreeItem<Person>(person);
        root.getChildren().add(p);
    }

    stage.show();


}

是否有人知道此修复/解决方案,或者这是TreeTableView的已知错误?

编辑:我刚试过这个例子

https://wikis.oracle.com/display/OpenJDK/TreeTableView+API+Examples

我仍然得到相同的行丢失/被删除的问题。

1 个答案:

答案 0 :(得分:1)

感谢@Alexander Kirov的解决方案。升级到build 104解决了这个问题。