Usecase for needsLayout property?
I'm having a bit of a chicken-egg problem with regards to some dynamically sized components I'm displaying in my application. Description: I have a group with a title that wraps some content and displays a title above it -- the entire group, including the title must be hidden and unmanaged when the content it is wrapping is empty, here it is in code: protected Pane createTitledBlock(final String title, final Node content, final BooleanExpression visibleCondition) { return new VBox() {{ setFillWidth(true); getChildren().add(new Label(title) {{ getStyleClass().add(header); }}); getChildren().add(content); if(visibleCondition != null) { managedProperty().bind(visibleCondition); visibleProperty().bind(visibleCondition); } }}; } Problem: When the content becomes available and visibleCondition gets toggled to true, the content part of the titled group is not yet laid out. This causes the title to be visible without any content briefly until a layout pass occurs. Timeline: - Group with title is hidden/unmanaged - The content gets updated and visibleCondition is set to true - Group with title becomes visible/managed - Briefly an empty group with title is displayed - Layout occurs, group with title gets resized Now, I'm thinking of playing with the needsLayout property and delaying the making visible/managed of the titled group until needsLayout is false... however, I have a feeling that won't work as an unmanaged/hidden group is probably not gonna participate in the layout, resulting in needsLayout never becoming false again as it is not visible/managed yet... Any ideas how I could resolve this, and have the group with title only visible and managed when it is properly laid out? Also, has any progress in general been made with regards to hidden/unmanaged controls and determining their expected size when they're made visible/managed? --John
Re: Usecase for needsLayout property?
Hi John, the problem you described is most likely caused by something else as the layout pass occurs BEFORE the actual rendering. Also, you bind managed and visible of the entire VBox, not just the title. So it's strange that you see Label correctly laid-out, but not the content. Can you make some sample and attach it to a JIRA issue, so I can have a look what's actually happening there? Thanks, -Martin On 06/05/2013 11:29 AM, John Hendrikx wrote: I'm having a bit of a chicken-egg problem with regards to some dynamically sized components I'm displaying in my application. Description: I have a group with a title that wraps some content and displays a title above it -- the entire group, including the title must be hidden and unmanaged when the content it is wrapping is empty, here it is in code: protected Pane createTitledBlock(final String title, final Node content, final BooleanExpression visibleCondition) { return new VBox() {{ setFillWidth(true); getChildren().add(new Label(title) {{ getStyleClass().add(header); }}); getChildren().add(content); if(visibleCondition != null) { managedProperty().bind(visibleCondition); visibleProperty().bind(visibleCondition); } }}; } Problem: When the content becomes available and visibleCondition gets toggled to true, the content part of the titled group is not yet laid out. This causes the title to be visible without any content briefly until a layout pass occurs. Timeline: - Group with title is hidden/unmanaged - The content gets updated and visibleCondition is set to true - Group with title becomes visible/managed - Briefly an empty group with title is displayed - Layout occurs, group with title gets resized Now, I'm thinking of playing with the needsLayout property and delaying the making visible/managed of the titled group until needsLayout is false... however, I have a feeling that won't work as an unmanaged/hidden group is probably not gonna participate in the layout, resulting in needsLayout never becoming false again as it is not visible/managed yet... Any ideas how I could resolve this, and have the group with title only visible and managed when it is properly laid out? Also, has any progress in general been made with regards to hidden/unmanaged controls and determining their expected size when they're made visible/managed? --John
Re: Usecase for needsLayout property?
Thanks Martin, I've done my best to quickly extract the code from my application... however, I cannot reproduce the issue there in a direct fashion -- however, I did discover an issue which may be the reason I see a partial group, I filed that as RT-30952 (TilePane doesn't appear until after Stage resized a bit). Basically, my main application is much more active, and will do a lot of background stuff, which may trigger more layouts -- that's why there I may only see the partial group for a moment (flickering when I scroll through the big list) before it gets displayed completely. In this test application, I see it much more directly where the group that I want to see is simply not complete until more action is taken. I also filed another issue, RT-30951 because the resizing of a Stage is very jittery (the controls keep moving a bit from their correct positions when in the process of resizing a Stage)... seems like some font-metrics or other calculation is not producing repeatable results resulting in a slightly different layout every time... --John On 5/06/2013 13:04, Martin Sladecek wrote: Hi John, the problem you described is most likely caused by something else as the layout pass occurs BEFORE the actual rendering. Also, you bind managed and visible of the entire VBox, not just the title. So it's strange that you see Label correctly laid-out, but not the content. Can you make some sample and attach it to a JIRA issue, so I can have a look what's actually happening there? Thanks, -Martin On 06/05/2013 11:29 AM, John Hendrikx wrote: I'm having a bit of a chicken-egg problem with regards to some dynamically sized components I'm displaying in my application. Description: I have a group with a title that wraps some content and displays a title above it -- the entire group, including the title must be hidden and unmanaged when the content it is wrapping is empty, here it is in code: protected Pane createTitledBlock(final String title, final Node content, final BooleanExpression visibleCondition) { return new VBox() {{ setFillWidth(true); getChildren().add(new Label(title) {{ getStyleClass().add(header); }}); getChildren().add(content); if(visibleCondition != null) { managedProperty().bind(visibleCondition); visibleProperty().bind(visibleCondition); } }}; } Problem: When the content becomes available and visibleCondition gets toggled to true, the content part of the titled group is not yet laid out. This causes the title to be visible without any content briefly until a layout pass occurs. Timeline: - Group with title is hidden/unmanaged - The content gets updated and visibleCondition is set to true - Group with title becomes visible/managed - Briefly an empty group with title is displayed - Layout occurs, group with title gets resized Now, I'm thinking of playing with the needsLayout property and delaying the making visible/managed of the titled group until needsLayout is false... however, I have a feeling that won't work as an unmanaged/hidden group is probably not gonna participate in the layout, resulting in needsLayout never becoming false again as it is not visible/managed yet... Any ideas how I could resolve this, and have the group with title only visible and managed when it is properly laid out? Also, has any progress in general been made with regards to hidden/unmanaged controls and determining their expected size when they're made visible/managed? --John