Update TableView resize policy to match changes in JFX20

This commit is contained in:
mkpaz 2023-05-26 15:53:47 +04:00
parent 6ef6b5502c
commit d9cd61f7fb
3 changed files with 98 additions and 30 deletions

@ -157,7 +157,9 @@ public final class TableViewPage extends OutlinePage {
var table = new TableView<>(Flight.random(5));
table.getColumns().setAll(col1, col2, col3, col4);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setColumnResizePolicy(
TableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN
);
table.getSelectionModel().selectFirst();
//snippet_1:end
@ -198,7 +200,9 @@ public final class TableViewPage extends OutlinePage {
var table = new TableView<>(Flight.random(5));
table.getColumns().setAll(col1, col2, col3, col4);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setColumnResizePolicy(
TableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN
);
table.getSelectionModel().selectFirst();
var borderToggle = new ToggleSwitch("Bordered");
@ -272,7 +276,9 @@ public final class TableViewPage extends OutlinePage {
// -color-cell-bg-selected-focused: -color-accent-emphasis;
// -color-cell-fg-selected-focused: -color-fg-emphasis;
table.setStyle(style);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setColumnResizePolicy(
TableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN
);
table.getSelectionModel().selectFirst();
//snippet_3:end
@ -314,7 +320,9 @@ public final class TableViewPage extends OutlinePage {
var table = new TableView<>(Flight.random(5));
table.getColumns().setAll(col1, col2, col3, col4);
table.getStyleClass().add(Tweaks.EDGE_TO_EDGE);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setColumnResizePolicy(
TableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN
);
table.getSelectionModel().selectFirst();
//snippet_5:end
@ -364,7 +372,9 @@ public final class TableViewPage extends OutlinePage {
var table = new TableView<>(Flight.random(5));
table.getColumns().setAll(col1, col2, col3, col4);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setColumnResizePolicy(
TableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN
);
table.getSelectionModel().selectFirst();
//snippet_6:end
@ -484,7 +494,9 @@ public final class TableViewPage extends OutlinePage {
var table = new TableView<>(Flight.random(5));
table.getColumns().setAll(col1, col2, col3);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setColumnResizePolicy(
TableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN
);
table.getSelectionModel().selectFirst();
//snippet_8:end
@ -524,7 +536,9 @@ public final class TableViewPage extends OutlinePage {
var table = new TableView<>(Flight.random(50));
table.getColumns().setAll(col1, col2, col3, col4);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setColumnResizePolicy(
TableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN
);
table.getSelectionModel().selectFirst();
var pg = new Pagination(25, 0);
@ -678,14 +692,34 @@ public final class TableViewPage extends OutlinePage {
}
});
final var unconResizeItem = new RadioMenuItem("Unconstrained");
unconResizeItem.setToggleGroup(resizePolGroup);
unconResizeItem.setUserData(TableView.UNCONSTRAINED_RESIZE_POLICY);
unconResizeItem.setSelected(true);
final var sizeUnconstrainedItem = new RadioMenuItem("Unconstrained");
sizeUnconstrainedItem.setToggleGroup(resizePolGroup);
sizeUnconstrainedItem.setUserData(TableView.UNCONSTRAINED_RESIZE_POLICY);
sizeUnconstrainedItem.setSelected(true);
final var conResizeItem = new RadioMenuItem("Constrained");
conResizeItem.setToggleGroup(resizePolGroup);
conResizeItem.setUserData(TableView.CONSTRAINED_RESIZE_POLICY);
final var sizeAllColumnsItem = new RadioMenuItem("Resize All Columns");
sizeAllColumnsItem.setToggleGroup(resizePolGroup);
sizeAllColumnsItem.setUserData(TableView.CONSTRAINED_RESIZE_POLICY_ALL_COLUMNS);
final var sizeLastColumnItem = new RadioMenuItem("Resize Last Column");
sizeLastColumnItem.setToggleGroup(resizePolGroup);
sizeLastColumnItem.setUserData(TableView.CONSTRAINED_RESIZE_POLICY_LAST_COLUMN);
final var sizeNextColumnItem = new RadioMenuItem("Resize Next Column");
sizeNextColumnItem.setToggleGroup(resizePolGroup);
sizeNextColumnItem.setUserData(TableView.CONSTRAINED_RESIZE_POLICY_NEXT_COLUMN);
final var sizeSubsequentItem = new RadioMenuItem("Resize Subsequent Column");
sizeSubsequentItem.setToggleGroup(resizePolGroup);
sizeSubsequentItem.setUserData(TableView.CONSTRAINED_RESIZE_POLICY_SUBSEQUENT_COLUMNS);
final var sizeFlexHeadItem = new RadioMenuItem("Flex Head");
sizeFlexHeadItem.setToggleGroup(resizePolGroup);
sizeFlexHeadItem.setUserData(TableView.CONSTRAINED_RESIZE_POLICY_FLEX_NEXT_COLUMN);
final var sizeFlexTailItem = new RadioMenuItem("Flex Tail");
sizeFlexTailItem.setToggleGroup(resizePolGroup);
sizeFlexTailItem.setUserData(TableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN);
// ~
@ -721,8 +755,14 @@ public final class TableViewPage extends OutlinePage {
final var propsMenu = new MenuButton("Properties");
propsMenu.getItems().setAll(
resizePolCaption,
unconResizeItem,
conResizeItem,
sizeUnconstrainedItem,
sizeAllColumnsItem,
sizeLastColumnItem,
sizeNextColumnItem,
sizeSubsequentItem,
sizeFlexHeadItem,
sizeFlexTailItem,
new SeparatorMenuItem(),
selModeCaption,
singleSelItem,
multiSelItem,

@ -88,7 +88,9 @@ public final class TreeTableViewPage extends OutlinePage {
);
var treeTable = new TreeTableView<Vehicle>();
treeTable.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
treeTable.setColumnResizePolicy(
TreeTableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN
);
treeTable.getColumns().setAll(col1, col2);
var make1 = FAKER.vehicle().make();
@ -268,22 +270,42 @@ public final class TreeTableViewPage extends OutlinePage {
private MenuButton createPropertiesMenu(TreeTableView<Product> treeTable) {
final var resizePolCaption = new CaptionMenuItem("Resize Policy");
final var resizePolicyGroup = new ToggleGroup();
resizePolicyGroup.selectedToggleProperty().addListener((obs, old, val) -> {
final var resizePolGroup = new ToggleGroup();
resizePolGroup.selectedToggleProperty().addListener((obs, old, val) -> {
if (val != null && val.getUserData() instanceof Callback<?, ?> policy) {
//noinspection rawtypes,unchecked
treeTable.setColumnResizePolicy((Callback<TreeTableView.ResizeFeatures, Boolean>) policy);
}
});
final var unconResizeItem = new RadioMenuItem("Unconstrained");
unconResizeItem.setToggleGroup(resizePolicyGroup);
unconResizeItem.setUserData(TreeTableView.UNCONSTRAINED_RESIZE_POLICY);
unconResizeItem.setSelected(true);
final var sizeUnconstrainedItem = new RadioMenuItem("Unconstrained");
sizeUnconstrainedItem.setToggleGroup(resizePolGroup);
sizeUnconstrainedItem.setUserData(TreeTableView.UNCONSTRAINED_RESIZE_POLICY);
sizeUnconstrainedItem.setSelected(true);
final var conResizeItem = new RadioMenuItem("Constrained");
conResizeItem.setToggleGroup(resizePolicyGroup);
conResizeItem.setUserData(TreeTableView.CONSTRAINED_RESIZE_POLICY);
final var sizeAllColumnsItem = new RadioMenuItem("Resize All Columns");
sizeAllColumnsItem.setToggleGroup(resizePolGroup);
sizeAllColumnsItem.setUserData(TreeTableView.CONSTRAINED_RESIZE_POLICY_ALL_COLUMNS);
final var sizeLastColumnItem = new RadioMenuItem("Resize Last Column");
sizeLastColumnItem.setToggleGroup(resizePolGroup);
sizeLastColumnItem.setUserData(TreeTableView.CONSTRAINED_RESIZE_POLICY_LAST_COLUMN);
final var sizeNextColumnItem = new RadioMenuItem("Resize Next Column");
sizeNextColumnItem.setToggleGroup(resizePolGroup);
sizeNextColumnItem.setUserData(TreeTableView.CONSTRAINED_RESIZE_POLICY_NEXT_COLUMN);
final var sizeSubsequentItem = new RadioMenuItem("Resize Subsequent Column");
sizeSubsequentItem.setToggleGroup(resizePolGroup);
sizeSubsequentItem.setUserData(TreeTableView.CONSTRAINED_RESIZE_POLICY_SUBSEQUENT_COLUMNS);
final var sizeFlexHeadItem = new RadioMenuItem("Flex Head");
sizeFlexHeadItem.setToggleGroup(resizePolGroup);
sizeFlexHeadItem.setUserData(TreeTableView.CONSTRAINED_RESIZE_POLICY_FLEX_NEXT_COLUMN);
final var sizeFlexTailItem = new RadioMenuItem("Flex Tail");
sizeFlexTailItem.setToggleGroup(resizePolGroup);
sizeFlexTailItem.setUserData(TreeTableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN);
// ~
@ -356,8 +378,14 @@ public final class TreeTableViewPage extends OutlinePage {
final var propsMenu = new MenuButton("Properties");
propsMenu.getItems().setAll(
resizePolCaption,
unconResizeItem,
conResizeItem,
sizeUnconstrainedItem,
sizeAllColumnsItem,
sizeLastColumnItem,
sizeNextColumnItem,
sizeSubsequentItem,
sizeFlexHeadItem,
sizeFlexTailItem,
new SeparatorMenuItem(),
selModeCaption,
singleSelItem,
multiSelItem,

@ -63,7 +63,7 @@ final class IconBrowser extends TableView<List<Ikon>> {
getColumns().add(col);
}
setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY_ALL_COLUMNS);
getSelectionModel().setCellSelectionEnabled(true);
getStyleClass().add("icon-browser");
}
@ -128,4 +128,4 @@ final class IconBrowser extends TableView<List<Ikon>> {
setGraphic(root);
}
}
}
}