Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make nested JavaFX GridPanes layout correctly?
    primarykey
    data
    text
    <p><strong>Context:</strong> I am building a JavaFX application with java1.7.0_07 and Jython. My application has a ScrollPane that contains a GridPane that contains a variable number of GridPanes. My application <em>discards and rebuilds the innermost GridPanes</em> each time a TreeView selection changes.</p> <p><strong>Problem:</strong> When I select something in the TreeView, the innermost GridPanes are <em>huge</em>, pushing all but the first innermost GridPane outside of the viewable area of the the ScrollPane. Regardless, the ScrollPane does not display scroll bars, giving the impression that there is only one innermost GridPane object. Manually resizing the window that contains the ScrollPane 'fixes' things! How can I get the innermost GridPanes to be that size from the moment that I add them?</p> <p>Of course, the first thing I tried was to call <code>requestLayout()</code> on the outer GridPane from the Jython interpreter, and this works just as well as resizing the containing window. This is also how I discovered that the innermost GridPanes were huge---I called <code>getBoundsInParent()</code> on each of the innermost GridPanes.</p> <p>However, inside of my <code>ChangeListener.changed()</code> implementation, everything is different. Calling <code>requestLayout()</code> does not seem to do anything. Moreover, the bounds of each of my innermost GridPanes is <code>[0,0,0,0]</code>! It looks like there is something asynchronous going on here, but I am new to JavaFX and I do not know what.</p> <p><strong>Update:</strong> Getting closer! Each of the innermost GridPanes contains a <code>Label</code>, and I am calling <code>setWrapText(true)</code> on each of the Labels. <em>If I do not enable wrapping on the Labels, the layout behaves correctly!</em> If I call <code>setPrefHeight(40)</code> on each of the Labels, the layout behaves correctly even with text wrapping enabled, but I really dislike the idea of trying to guess an appropriate preferred height to assign to each of my Labels. I just want the Labels to start with the bounds that they assume when I 'wiggle' the containing window. But how?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload