JDK-8091269 : Cannot set initial column sizes with CONSTRAINED_RESIZE_POLICY
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2013-12-20
  • Updated: 2023-01-04
  • Resolved: 2023-01-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Blocks :  
Duplicate :  
Description
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.
Comments
This issue is effectively a duplicate of JDK-8293119. With JDK-8293119, the CONSTRAINED_RESIZE_POLICY will honor the columns' preferred widths and handle any subsequent manual resizing correctly.
04-01-2023