Need help to fix the display issue on table view JavaFX.
I can't paste full code. but, will try to include maximum.
TextField headerTextField = new TextField();
Label label = new Label((String) allColumns[i]);
VBox headerGraphic = new VBox();
headerGraphic.setAlignment(Pos.CENTER);
headerGraphic.getChildren().addAll(label, headerTextField);
TableColumn tableColumn = new TableColumn<>();
tableColumn.setGraphic(headerGraphic);
if I don't set graphics and directly create a table column with a column name, it looks good.
TableColumn tableColumn = new TableColumn<>((String) allColumns[i]);
Updates: I resolved it by using Text instead of Label. Seems that Label's width is calculated only after Scene is loaded. Hence, the table column pref width was not set.
With the code below, it worked.
TextField headerTextField = new TextField();
Text label = new Text((String) allColumns[i]);
VBox headerGraphic = new VBox();
headerGraphic.setAlignment(Pos.CENTER);
headerGraphic.getChildren().addAll(label, headerTextField);
TableColumn tableColumn = new TableColumn<>();
tableColumn.setGraphic(headerGraphic);