A DESCRIPTION OF THE REQUEST :
TableView uses an VirtualFlow to calculate the ViewPort
wenn use tablewView in Layouts (TabPane / GridPane)
in some cases it is needed, that the Table schows all items
-> the TableView size must set as ViewPort size
JUSTIFICATION :
open detail.png:
an Detail Tab shows additional informations over an Item
in every Tab in this Detail it shows an TableView wird linked items:
* an Items has a place
* a place has items on it
* user has groups / rights
* ...
in this Detail it is needed that only one Scrpallpane is Present
so alle Tabs / Tableview in tabPane must use USE_PREF_SIZE
to set width / heigt so that all items are directly visible
---------- BEGIN SOURCE ----------
http://194.25.240.197:9980/MemoryTable.zip
[add Tabs] / [add Cells]
use [hack] to active the height / width calculation
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
// wait Skin is set
view.skinProperty().addListener((ov, from, to) -> {
try {
// cast
final TableViewSkin<?> skin = (TableViewSkin<?>) to;
// ugly hack 1: get VirtualFlow
final Field flowField = VirtualContainerBase.class.getDeclaredField("flow");
flowField.setAccessible(true);
final VirtualFlow<?> flow = (VirtualFlow<?>) flowField.get(skin);
// ugly hack 2: get Methods to calc real ViewPort size
final Method getMaxCellWidth = VirtualContainerBase.class.getDeclaredMethod("getMaxCellWidth", int.class);
getMaxCellWidth.setAccessible(true);
final Method getVirtualFlowPreferredHeight = VirtualContainerBase.class.getDeclaredMethod("getVirtualFlowPreferredHeight", int.class);
getVirtualFlowPreferredHeight.setAccessible(true);
final InvalidationListener invalidation = (value) -> {
Platform.runLater(() -> {
try {
// ugly hack 3: calc ViewPort size
final double width = (double) getMaxCellWidth.invoke(skin, view.getItems().size()) + 15;
final double height = (double) getVirtualFlowPreferredHeight.invoke(skin, view.getItems().size()) + 15 + skin.getTableHeaderRow().getHeight();
// set Size on tyble View
// no space on bottom
// only needed ells are created
view.setMinSize(width, height);
view.setPrefSize(width, height);
view.setMaxSize(width, height);
System.out.println(width + " " + height);
} catch (final Throwable throwable) {
throwable.printStackTrace();
}
});
};
// invalidations to trigger the calculation
flow.widthProperty().addListener(invalidation);
flow.heightProperty().addListener(invalidation);
view.itemsProperty().addListener(invalidation);
for (final TableColumn<?, ?> tc : view.getColumns()) {
tc.widthProperty().addListener(invalidation);
}
} catch (final Throwable throwable) {
throwable.printStackTrace();
}
});
TableView uses an VirtualFlow to calculate the ViewPort
wenn use tablewView in Layouts (TabPane / GridPane)
in some cases it is needed, that the Table schows all items
-> the TableView size must set as ViewPort size
JUSTIFICATION :
open detail.png:
an Detail Tab shows additional informations over an Item
in every Tab in this Detail it shows an TableView wird linked items:
* an Items has a place
* a place has items on it
* user has groups / rights
* ...
in this Detail it is needed that only one Scrpallpane is Present
so alle Tabs / Tableview in tabPane must use USE_PREF_SIZE
to set width / heigt so that all items are directly visible
---------- BEGIN SOURCE ----------
http://194.25.240.197:9980/MemoryTable.zip
[add Tabs] / [add Cells]
use [hack] to active the height / width calculation
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
// wait Skin is set
view.skinProperty().addListener((ov, from, to) -> {
try {
// cast
final TableViewSkin<?> skin = (TableViewSkin<?>) to;
// ugly hack 1: get VirtualFlow
final Field flowField = VirtualContainerBase.class.getDeclaredField("flow");
flowField.setAccessible(true);
final VirtualFlow<?> flow = (VirtualFlow<?>) flowField.get(skin);
// ugly hack 2: get Methods to calc real ViewPort size
final Method getMaxCellWidth = VirtualContainerBase.class.getDeclaredMethod("getMaxCellWidth", int.class);
getMaxCellWidth.setAccessible(true);
final Method getVirtualFlowPreferredHeight = VirtualContainerBase.class.getDeclaredMethod("getVirtualFlowPreferredHeight", int.class);
getVirtualFlowPreferredHeight.setAccessible(true);
final InvalidationListener invalidation = (value) -> {
Platform.runLater(() -> {
try {
// ugly hack 3: calc ViewPort size
final double width = (double) getMaxCellWidth.invoke(skin, view.getItems().size()) + 15;
final double height = (double) getVirtualFlowPreferredHeight.invoke(skin, view.getItems().size()) + 15 + skin.getTableHeaderRow().getHeight();
// set Size on tyble View
// no space on bottom
// only needed ells are created
view.setMinSize(width, height);
view.setPrefSize(width, height);
view.setMaxSize(width, height);
System.out.println(width + " " + height);
} catch (final Throwable throwable) {
throwable.printStackTrace();
}
});
};
// invalidations to trigger the calculation
flow.widthProperty().addListener(invalidation);
flow.heightProperty().addListener(invalidation);
view.itemsProperty().addListener(invalidation);
for (final TableColumn<?, ?> tc : view.getColumns()) {
tc.widthProperty().addListener(invalidation);
}
} catch (final Throwable throwable) {
throwable.printStackTrace();
}
});