Reputation: 3119
I have a table with three columns and I want to make sure the total width of the columns is equal to the width of the table, so I'm using CONSTRAINED_RESIZE_POLICY.
I want the columns to start with a width I specify, but can be modified by the user.
If I do this:
albumTable.setColumnResizePolicy ( TableView.CONSTRAINED_RESIZE_POLICY );
artistColumn.prefWidthProperty().bind(albumTable.widthProperty().multiply(0.4));
yearColumn.prefWidthProperty().bind(albumTable.widthProperty().multiply(0.2));
albumColumn.prefWidthProperty().bind(albumTable.widthProperty().multiply(0.4));
artistColumn.setResizable(false);
yearColumn.setResizable(false);
albumColumn.setResizable(false);
The columns are sized as i want:
But if I change setResizable()
to true
, then the columns all become the same size:
Any suggestions on how I can fix this?
Simplifying the setting of preferred width to something like column.setPreferredWidth ( 200 )
doesn't make any difference. The width is always divided evenly between all columns.
Is there any way to set the preferred width (or actual width) of columns while still allowing those columns to be resized by the user?
Upvotes: 1
Views: 674
Reputation: 884
It seems that CONSTRAINED_RESIZE_POLICY
starts with the ratio of column's maximum width. To start at a ratio of 4:2:4,
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
column1.setResizable(true);
column2.setResizable(true);
column3.setResizable(true);
column1.setMaxWidth(40000);
column2.setMaxWidth(20000);
column3.setMaxWidth(40000);
This method may solve the problem just when radio is required.
Upvotes: 2