I am trying to get the width of a TableView object as wide as the accumulated sums of all TableColumns, so that the Table is fully shown without a scrollbar. The table is inside a grid Layout, and i tried getting the width of all columns together with the following code:
private double getTableWidth(TableView dataTable){
double totalWidth = 0;
for(int i = 0; i < dataTable.getColumns().size(); i++){
totalWidth += ((TableColumn) dataTable.getColumns().get(i)).getWidth();
}
return totalWidth;
}
But somehow the width for each column is 80, even if they look different wide.
To set the width of the table i use the following:
dataTable.setMinWidth(getTableWidth(dataTable));
Note: I start with a TableView-Object with the following code:
children>
<TableView fx:id="dataTable" prefHeight="451.0" prefWidth="701.0" />
</children>
and fill the table by creating TableColumns without a width parameter or anything.