As far as I can see, there is no way to set the initial width of the columns in a TableView when you're using a CONSTRAINED_RESIZE_POLICY. As soon as you set the policy, all resizable columns are immediately given an equal share of the available space, regardless of what their width or prefwidth is currently set to. Even calling TableView.resizeColumn() doesn't work, because the CONSTRAINED_RESIZE_POLICY keeps giving/taking space from the last column in the table.
This is a problem if you want to save the table column widths when the user shuts down your application and restore them when the user restarts. For now we are forced to use UNCONSTRAINED_RESIZE_POLICY in order to have this behaviour.
Potential solutions:
1) change CONSTRAINED_RESIZE_POLICY to respect the initial width or prefwidth of the columns at the moment it is installed, so the user can set initial column sizes, and then install the policy.
OR
2) create a new kind of constrained RESIZE_POLICY that behaves like the old Swing JTable: all extra space is distributed evenly among the resizeable columns when the user resizes columns, and thus Table.resizeColumn() can be used to set up the initial size of the columns even after the policy is installed.
I prefer option 2 because (on an unrelated note) I think distributing extra space among ALL columns during a column resize is more intuitive than forcing all the extra space onto the right-most column.
This is a problem if you want to save the table column widths when the user shuts down your application and restore them when the user restarts. For now we are forced to use UNCONSTRAINED_RESIZE_POLICY in order to have this behaviour.
Potential solutions:
1) change CONSTRAINED_RESIZE_POLICY to respect the initial width or prefwidth of the columns at the moment it is installed, so the user can set initial column sizes, and then install the policy.
OR
2) create a new kind of constrained RESIZE_POLICY that behaves like the old Swing JTable: all extra space is distributed evenly among the resizeable columns when the user resizes columns, and thus Table.resizeColumn() can be used to set up the initial size of the columns even after the policy is installed.
I prefer option 2 because (on an unrelated note) I think distributing extra space among ALL columns during a column resize is more intuitive than forcing all the extra space onto the right-most column.
- blocks
-
JDK-8292810 ☂ CONSTRAINED_RESIZE_POLICY issues
- Resolved
- duplicates
-
JDK-8293119 Additional constrained resize policies for Tree/TableView
- Resolved