Skip to content

Conversation

@hjohn
Copy link
Collaborator

@hjohn hjohn commented Nov 29, 2025

This fixes a long standing bug with GridPane where unmanaged nodes would still result in gaps being added between rows/columns even though nothing is rendered there. Take the following grid where dashes and pipes represent the vgaps and hgaps:

0 1
0 A | B
- | -
1 C | D
- | -
2 E | F

Now, when both C and D are set to unmanaged (and invisible) the grid will still render the gaps:

0 1
0 A | B
- | -
1 |
- | -
2 E | F

Instead it should collapse the gap between row 0 and 2:

0 1
0 A | B
- | -
2 E | F

There are at least two relevant issues in JBS:

  • A request to let the user show and hide rows and columns: https://bugs.openjdk.org/browse/JDK-8136901
    • This can now be done by setting the relevant row/columns items to unmanaged without having to restructure the grid (assuming the complaint was that otherwise there'd be visible extra gaps for each hidden row)
  • A request for another mode to skip gaps when entire rows/columns are unmanaged: https://bugs.openjdk.org/browse/JDK-8092379
    • This should not be a mode, but the standard, as unmanaged nodes should not affect the outcome of the grid layout

Screenshots

Simple application which can hide row 3:

image

Correct behavior when row 3 is hidden:

image

Behavior before this fix (note the double gap and extra grid line):

image

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8092379: GridPane should not render extra gaps when entire rows or columns are unmanaged (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1990/head:pull/1990
$ git checkout pull/1990

Update a local copy of the PR:
$ git checkout pull/1990
$ git pull https://git.openjdk.org/jfx.git pull/1990/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1990

View PR using the GUI difftool:
$ git pr show -t 1990

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1990.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 29, 2025

👋 Welcome back jhendrikx! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Nov 29, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@hjohn hjohn changed the title When all nodes starting in a row or column are unmanaged, skip gap JDK-8092379 GridPane should not render extra gaps when entire rows or columns are unmanaged. Nov 29, 2025
@openjdk openjdk bot changed the title JDK-8092379 GridPane should not render extra gaps when entire rows or columns are unmanaged. 8092379: GridPane should not render extra gaps when entire rows or columns are unmanaged. Nov 29, 2025
@openjdk openjdk bot added the rfr Ready for review label Nov 29, 2025
@hjohn hjohn changed the title 8092379: GridPane should not render extra gaps when entire rows or columns are unmanaged. 8092379: GridPane should not render extra gaps when entire rows or columns are unmanaged Nov 29, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 29, 2025

Webrevs

@hjohn hjohn force-pushed the feature/grid-proper-gaps branch from 324eb9c to 69eedce Compare November 29, 2025 20:48
@openjdk
Copy link

openjdk bot commented Nov 29, 2025

@hjohn Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

@andy-goryachev-oracle
Copy link
Contributor

/reviewers 2

@openjdk
Copy link

openjdk bot commented Dec 1, 2025

@andy-goryachev-oracle
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

I've updated the standalone Monkey Tester to add a couple of layout scenarios to the GridPane page.

Interval i = new Interval(startPosition, endPosition);
multiSizes.put(i, size);
private void setMaxSize(int position, double size) {
singleSizes[position] = Math.max(singleSizes[position], size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why github shows this as a change.
Unused setMultiSize() has been removed which is ok.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's confusing the start of the diff I think :)

private Iterable<Entry<Interval, Double>> multiSizes() {
if (multiSizes == null) {
return Collections.EMPTY_LIST;
return Collections.emptyList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change, and probably gets inlined anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, could remove, I just made the change because it was giving a raw type warning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I turned the raw warnings off, the project has thousands of those...

@hjohn
Copy link
Collaborator Author

hjohn commented Dec 1, 2025

Looks good.

I've updated the standalone Monkey Tester to add a couple of layout scenarios to the GridPane page.

Thanks, GridPane is quite a useful layout, but if you want to hide a row or column, it is a huge pain currently (unless you use hgap/vgap of 0) as you need to physically renumber your rows/columns to collapse the extra gaps...

@andy-goryachev-oracle
Copy link
Contributor

huge pain, yes, that's why I am still working on https://github.com/andy-goryachev/FxDock/blob/master/doc/CPane.md

@hjohn
Copy link
Collaborator Author

hjohn commented Dec 1, 2025

huge pain, yes, that's why I am still working on https://github.com/andy-goryachev/FxDock/blob/master/doc/CPane.md

:-)

I created my own Flex layout, which is a combination of HBox + VBox + GridPane. It basically works by looking at how they are nested. If you nest multiple horizontal flexes into a vertical flex:

 FlexV
       FlexH [ label , text field ]
       FlexH [ label , text field ]

The above would produce an unaligned mess when the labels are different lengths, just like nesting HBoxes into VBox would. However, the Flex has a property "aligned" that you can set, and it will affect the layout of any nested flexes of the opposite type. In this case, if you give the top FlexV this property, the nested horizontal flexes will automatically align as if they were in a grid.

It looks like this in code (in builder form):

    Panes.vflex("form").aligned().nodes(
      Panes.hflex().nodes(
        "Width",
        FX.spinner().editable().value(parameters.width)
      ),
      XPanes.hflex().nodes(
        "Height",
        FX.spinner().editable().value(parameters.height)
      )
    );

I actually only use GridPane in my samples, as I'm not ready yet to publish Flex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rfr Ready for review

Development

Successfully merging this pull request may close these issues.

2 participants