【问题标题】:JavaFX TreeTableView rows gone when scrolling滚动时JavaFX TreeTableView行消失
【发布时间】:2013-08-28 17:41:57
【问题描述】:

我一直在试验JDK 8 中的TreeTableView。在我的程序启动并运行后,我注意到一个问题,当我滚动时,行会被空白。我已经尝试了一切,从重置单元格的可见性、更新时、希望它在更新时重绘,甚至重置列的可见性。这是我编写的一个测试小程序,用于显示当您滚动查看树表视图时,行会被空白,但对于表视图,情况并非如此。

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

我仍然遇到同样的问题,即行丢失/被白化。

【问题讨论】:

  • 你使用哪个版本的 jdk8?
  • 我不太确定我使用的是哪个版本(有办法检查吗?)如果有帮助,我会在 2013 年 8 月 8 日下载它。
  • java -version 会输出 8.0-b### 之类的东西,我大概是 ###...
  • b101.我应该更新到较新的版本吗?
  • 我下载了 build 104,这解决了这个问题。非常感谢!

标签: java javafx-8


【解决方案1】:

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

【讨论】:

  • 通常情况下,您可以使用 javafx-jira 获取有关现有错误的信息。 (是的,javafx 中有错误 :))你也可以提交你的文件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多