Details
-
Bug
-
Resolution: Fixed
-
P4
-
7u25
-
None
Description
The following code shows a gridpane with two columns. Column widths are changed on a timeline.
Expected: columns resize visually, on screen.
Actual: nothing seems to happen unless layouting is forced by resizing the window.
To work around this I have to requestLayout on the gridpane manually whenever changing the column constraints. In my opinion, this should not really be necessary. A change of ColumnConstraints.prefWidths actually already requests a layout - but this is requested on the gridpane's parent (see ConstraintsBase.requestLayout). This does not trigger a layout on the gridpane itself. Also, subsequent changes to ColumnConstraints.prefWidthProperty may be ignored because invalidated is not called again after the property became invalidated before and the value was never used thereafter.
public class GridPaneSizingTest extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception
{
final GridPane grid = new GridPane();
final ColumnConstraints col1 = new ColumnConstraints(150);
final ColumnConstraints col2 = new ColumnConstraints(150);
grid.getColumnConstraints().addAll(col1, col2);
for (int i = 0; i < 15; i++)
{
grid.add(new Label("left"), 0, i);
grid.add(new Label("right"), 1, i);
}
grid.setGridLinesVisible(true);
StackPane pane = new StackPane();
pane.getChildren().add(grid);
primaryStage.setScene(new Scene(pane, 400, 300));
primaryStage.show();
TimelineBuilder.create()
.keyFrames(
new KeyFrame(
Duration.seconds(30),
new KeyValue(col1.prefWidthProperty(), 5),
new KeyValue(col2.prefWidthProperty(), 295)))
.build()
.play();
}
}
Expected: columns resize visually, on screen.
Actual: nothing seems to happen unless layouting is forced by resizing the window.
To work around this I have to requestLayout on the gridpane manually whenever changing the column constraints. In my opinion, this should not really be necessary. A change of ColumnConstraints.prefWidths actually already requests a layout - but this is requested on the gridpane's parent (see ConstraintsBase.requestLayout). This does not trigger a layout on the gridpane itself. Also, subsequent changes to ColumnConstraints.prefWidthProperty may be ignored because invalidated is not called again after the property became invalidated before and the value was never used thereafter.
public class GridPaneSizingTest extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception
{
final GridPane grid = new GridPane();
final ColumnConstraints col1 = new ColumnConstraints(150);
final ColumnConstraints col2 = new ColumnConstraints(150);
grid.getColumnConstraints().addAll(col1, col2);
for (int i = 0; i < 15; i++)
{
grid.add(new Label("left"), 0, i);
grid.add(new Label("right"), 1, i);
}
grid.setGridLinesVisible(true);
StackPane pane = new StackPane();
pane.getChildren().add(grid);
primaryStage.setScene(new Scene(pane, 400, 300));
primaryStage.show();
TimelineBuilder.create()
.keyFrames(
new KeyFrame(
Duration.seconds(30),
new KeyValue(col1.prefWidthProperty(), 5),
new KeyValue(col2.prefWidthProperty(), 295)))
.build()
.play();
}
}