I want to autoset the column-width programatically so that the table header is fitted to its content.
@Override
public void initialize(URL url, ResourceBundle rb) {
TableColumn<String, String> col1 = new TableColumn<>("C1");
TableColumn<String, String> col2 = new TableColumn<>("Column 2");
TableColumn<String, String> col3 = new TableColumn<>("Last Column (C3)");
TableColumn<String, String> col4 = new TableColumn<>("blablabla");
table.getColumns().add(col1);
table.getColumns().add(col2);
table.getColumns().add(col3);
table.getColumns().add(col4);
for(int i=0;i<4;i++) {
System.out.println("Column width >> "+table.getColumns().get(i).getPrefWidth());
}
}
The column-width of each header in a table is always set to a value of 80
. How can I get and set the the width values so that the header titles are visible in each column header?