当我在创建表后动态添加嵌套列时,嵌套列标题不会呈现。这是重现问题的代码。我正在使用 JDK 1.8.0_121
但是,如果我内联添加嵌套列,那么一切都会按预期显示。
package hellofx;
import javafx.application.*;
import javafx.application.*;
import javafx.geometry.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.text.*;
import javafx.stage.*;
public class TableViewSample extends Application {
private TreeTableView table = new TreeTableView();
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
Scene scene = new Scene(new Group());
stage.setTitle("Table View Sample");
stage.setWidth(600);
stage.setHeight(500);
final Label label = new Label("Address Book");
label.setFont(new Font("Arial", 20));
table.setEditable(true);
TreeTableColumn firstNameCol = new TreeTableColumn("First Name");
TreeTableColumn lastNameCol = new TreeTableColumn("Last Name");
TreeTableColumn emailCol = new TreeTableColumn("Email");
//Simulate adding nested columns after stage is set.
Platform.runLater(() -> {
TreeTableColumn firstEmailCol = new TreeTableColumn("Primary");
TreeTableColumn secondEmailCol = new TreeTableColumn("Secondary");
emailCol.getColumns().addAll(firstEmailCol, secondEmailCol);
});
table.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, table);
((Group) scene.getRoot()).getChildren().addAll(vbox);
stage.setScene(scene);
stage.show();
}
}