Summary
- Adding several new constrained resize policies, similar to JTable
- Replacing buggy Tree/TableView.CONSTRAINED_RESIZE_POLICY with a new implementation
- Adding new methods to make it possible to create user-defined Tree/TableView column resize policies
Problem
The current Tree/TableView.CONSTRAINED_RESIZE_POLICY has many, many issues, see JDK-8292810. One such issue is a complete inability to deal with over-constrained Tree/TableView.
In addition to that, any developer who wants to fix the situation by providing their own implementation (as suggested by existing setColumnResizePolicy() method) is simply unable to do so because no public APIs exist that allow for actually setting the column widths, or to obtain the target width.
Solution
First, public APIs are added to ResizeFeaturesBase
class to make sure the application developers can create a custom resize policy. These changes include:
- made ResizeFeaturesBase class abstract
- added
abstract getContentWidth()
- added
setColumnWidth(TableColumnBase, double);
- added
abstract getTableControl()
method to return the Tree/TableView control
Added a new abstract ConstrainedColumnResizeBase class which serves as a marker class to tell the skin to disable the horizontal scroll bar.
Added a number of additional Tree/TableView column resize policies
- CONSTRAINED_RESIZE_POLICY_ALL_COLUMNS
- CONSTRAINED_RESIZE_POLICY_LAST_COLUMN
- CONSTRAINED_RESIZE_POLICY_NEXT_COLUMN
- CONSTRAINED_RESIZE_POLICY_SUBSEQUENT_COLUMNS
- CONSTRAINED_RESIZE_POLICY_FLEX_NEXT_COLUMN
- CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN
And finally, replaced the legacy CONSTRAINED_RESIZE_POLICY with a new bugless implementation CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN.
Specification
modules/javafx.controls/src/main/java/javafx/scene/control/ConstrainedColumnResizeBase.java
+package javafx.scene.control;
+
+/**
+ * Base class for a constrained column resize policy.
+ * Setting any policy that extends this class on a Tree/TableView results in
+ * disabling of its horizontal scroll bar.
+ *
+ * @see TableView#columnResizePolicyProperty
+ * @see TreeTableView#columnResizePolicyProperty
+ *
+ * @since 20
+ */
+public abstract class ConstrainedColumnResizeBase {
+ /**
+ * Constructor for subclasses to call.
+ */
+ public ConstrainedColumnResizeBase() {
+ }
+
+ @Override
+ public String toString() {
+ // name of a pseudo-style set on a Tree/TableView when a constrained resize policy is in effect
+ return "constrained-resize";
+ }
+}
modules/javafx.controls/src/main/java/javafx/scene/control/ResizeFeaturesBase.java
/**
- * An immutable wrapper class for use by the column resize policies offered by
+ * A wrapper class for use by the column resize policies offered by
* controls such as {@link TableView} and {@link TreeTableView}.
* @since JavaFX 8.0
*/
-public class ResizeFeaturesBase<S> {
+public abstract class ResizeFeaturesBase<S> {
/**
+ * Returns the width of the area available for columns.
+ *
+ * @return the width availabe for columns
+ *
+ * @since 20
+ */
+ public abstract double getContentWidth();
+
+ /**
+ * Returns the associated TreeView or TreeTableView control.
+ *
+ * @return the control in which the resize is occurring
+ *
+ * @since 20
+ */
+ public abstract Control getTableControl();
+ /**
+ * Sets the column width during the resizing pass.
+ *
+ * @param col column being changed
+ * @param width desired column width
+ *
+ * @since 20
+ */
+ public void setColumnWidth(TableColumnBase<S,?> col, double width) {
+ col.doSetWidth(width);
+ }
b/modules/javafx.controls/src/main/java/javafx/scene/control/TableView.java
+ * A resize policy that adjusts other columns in order to fit the table width.
+ * During UI adjustment, proportionately resizes all columns to preserve the total width.
+ * <p>
+ * When column constraints make it impossible to fit all the columns into the allowed area,
+ * the columns are either clipped, or an empty space appears. This policy disables the horizontal
+ * scroll bar.
+ *
+ * @since 20
+ */
+ public static final Callback<TableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_ALL_COLUMNS =
+ ConstrainedColumnResize.forTable(ConstrainedColumnResize.ResizeMode.AUTO_RESIZE_ALL_COLUMNS);
+
+ /**
+ * A resize policy that adjusts the last column in order to fit the table width.
+ * During UI adjustment, resizes the last column only to preserve the total width.
+ * <p>
+ * When column constraints make it impossible to fit all the columns into the allowed area,
+ * the columns are either clipped, or an empty space appears. This policy disables the horizontal
+ * scroll bar.
+ *
+ * @since 20
+ */
+ public static final Callback<TableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_LAST_COLUMN =
+ ConstrainedColumnResize.forTable(ConstrainedColumnResize.ResizeMode.AUTO_RESIZE_LAST_COLUMN);
+
+ /**
+ * A resize policy that adjusts the next column in order to fit the table width.
+ * During UI adjustment, resizes the next column the opposite way.
+ * <p>
+ * When column constraints make it impossible to fit all the columns into the allowed area,
+ * the columns are either clipped, or an empty space appears. This policy disables the horizontal
+ * scroll bar.
+ *
+ * @since 20
+ */
+ public static final Callback<TableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_NEXT_COLUMN =
+ ConstrainedColumnResize.forTable(ConstrainedColumnResize.ResizeMode.AUTO_RESIZE_NEXT_COLUMN);
+
+ /**
+ * A resize policy that adjusts subsequent columns in order to fit the table width.
+ * During UI adjustment, proportionally resizes subsequent columns to preserve the total width.
+ * <p>
+ * When column constraints make it impossible to fit all the columns into the allowed area,
+ * the columns are either clipped, or an empty space appears. This policy disables the horizontal
+ * scroll bar.
+ *
+ * @since 20
+ */
+ public static final Callback<TableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_SUBSEQUENT_COLUMNS =
+ ConstrainedColumnResize.forTable(ConstrainedColumnResize.ResizeMode.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
+
+ /**
+ * A resize policy that adjusts columns, starting with the next one, in order to fit the table width.
+ * During UI adjustment, resizes the next column to preserve the total width. When the next column
+ * cannot be further resized due to a constraint, the following column gets resized, and so on.
+ * <p>
+ * When column constraints make it impossible to fit all the columns into the allowed area,
+ * the columns are either clipped, or an empty space appears. This policy disables the horizontal
+ * scroll bar.
+ *
+ * @since 20
+ */
+ public static final Callback<TableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_FLEX_NEXT_COLUMN =
+ ConstrainedColumnResize.forTable(ConstrainedColumnResize.ResizeMode.AUTO_RESIZE_FLEX_HEAD);
+
+ /**
+ * A resize policy that adjusts columns, starting with the last one, in order to fit the table width.
+ * During UI adjustment, resizes the last column to preserve the total width. When the last column
+ * cannot be further resized due to a constraint, the column preceding the last one gets resized, and so on.
+ * <p>
+ * When column constraints make it impossible to fit all the columns into the allowed area,
+ * the columns are either clipped, or an empty space appears. This policy disables the horizontal
+ * scroll bar.
+ *
+ * @since 20
+ */
+ public static final Callback<TableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN =
+ ConstrainedColumnResize.forTable(ConstrainedColumnResize.ResizeMode.AUTO_RESIZE_FLEX_TAIL);
+
+ /**
* <p>Simple policy that ensures the width of all visible leaf columns in
...
+ *
+ * @deprecated Use {@link #CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN} instead.
*/
- public static final Callback<ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY = new Callback<>() {
...
+ @Deprecated(since="20")
+ public static final Callback<ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY =
+ CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN;
modules/javafx.controls/src/main/java/javafx/scene/control/TreeTableView.java
+ * A resize policy that adjusts other columns in order to fit the tree table width.
+ * During UI adjustment, proportionately resizes all columns to preserve the total width.
+ * <p>
+ * When column constraints make it impossible to fit all the columns into the allowed area,
+ * the columns are either clipped, or an empty space appears. This policy disables the horizontal
+ * scroll bar.
+ *
+ * @since 20
+ */
+ public static final Callback<TreeTableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_ALL_COLUMNS =
+ ConstrainedColumnResize.forTreeTable(ConstrainedColumnResize.ResizeMode.AUTO_RESIZE_ALL_COLUMNS);
+
+ /**
+ * A resize policy that adjusts the last column in order to fit the tree table width.
+ * During UI adjustment, resizes the last column only to preserve the total width.
+ * <p>
+ * When column constraints make it impossible to fit all the columns into the allowed area,
+ * the columns are either clipped, or an empty space appears. This policy disables the horizontal
+ * scroll bar.
+ *
+ * @since 20
+ */
+ public static final Callback<TreeTableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_LAST_COLUMN =
+ ConstrainedColumnResize.forTreeTable(ConstrainedColumnResize.ResizeMode.AUTO_RESIZE_LAST_COLUMN);
+
+ /**
+ * A resize policy that adjusts the next column in order to fit the tree table width.
+ * During UI adjustment, resizes the next column the opposite way.
+ * <p>
+ * When column constraints make it impossible to fit all the columns into the allowed area,
+ * the columns are either clipped, or an empty space appears. This policy disables the horizontal
+ * scroll bar.
+ *
+ * @since 20
+ */
+ public static final Callback<TreeTableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_NEXT_COLUMN =
+ ConstrainedColumnResize.forTreeTable(ConstrainedColumnResize.ResizeMode.AUTO_RESIZE_NEXT_COLUMN);
+
+ /**
+ * A resize policy that adjusts subsequent columns in order to fit the tree table width.
+ * During UI adjustment, proportionally resizes subsequent columns to preserve the total width.
+ * <p>
+ * When column constraints make it impossible to fit all the columns into the allowed area,
+ * the columns are either clipped, or an empty space appears. This policy disables the horizontal
+ * scroll bar.
+ *
+ * @since 20
+ */
+ public static final Callback<TreeTableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_SUBSEQUENT_COLUMNS =
+ ConstrainedColumnResize.forTreeTable(ConstrainedColumnResize.ResizeMode.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
+
+ /**
+ * A resize policy that adjusts columns, starting with the next one, in order to fit the tree table width.
+ * During UI adjustment, resizes the next column to preserve the total width. When the next column
+ * cannot be further resized due to a constraint, the following column gets resized, and so on.
+ * <p>
+ * When column constraints make it impossible to fit all the columns into the allowed area,
+ * the columns are either clipped, or an empty space appears. This policy disables the horizontal
+ * scroll bar.
+ *
+ * @since 20
+ */
+ public static final Callback<TreeTableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_FLEX_NEXT_COLUMN =
+ ConstrainedColumnResize.forTreeTable(ConstrainedColumnResize.ResizeMode.AUTO_RESIZE_FLEX_HEAD);
+
+ /**
+ * A resize policy that adjusts columns, starting with the last one, in order to fit the table width.
+ * During UI adjustment, resizes the last column to preserve the total width. When the last column
+ * cannot be further resized due to a constraint, the column preceding the last one gets resized, and so on.
+ * <p>
+ * When column constraints make it impossible to fit all the columns into the allowed area,
+ * the columns are either clipped, or an empty space appears. This policy disables the horizontal
+ * scroll bar.
+ *
+ * @since 20
+ */
+ public static final Callback<TreeTableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN =
+ ConstrainedColumnResize.forTreeTable(ConstrainedColumnResize.ResizeMode.AUTO_RESIZE_FLEX_TAIL);
+
+ /**
* <p>Simple policy that ensures the width of all visible leaf columns in
...
+ *
+ * @deprecated Use {@link #CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN} instead.
*/
+ @Deprecated(since="20")
public static final Callback<TreeTableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY =
- new Callback<>() {
...
+ CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN;
- csr of
-
JDK-8293119 Additional constrained resize policies for Tree/TableView
- Resolved