I have complex dynamically driven forms that build a panel within a scrollpane. Some of the controls are JTextArea's where the height would necessarily need to be adjusted to support word wrapping (i.e., they are not in scrollpane's of their own). Everything works fine if the panel display area is tall enough to support all the word wrapped text area's (i.e., the no scrolling is needed in the panel). It also works correctly if the panel is wide enough that the text area's do not require wrapping even if vertical scrolling is needed.
However, it has issues if any of the text area's require wrapping and the vertical space available in the panel is not enough to display all the controls after wrapping (i.e., scrolling is required). What appears to be happening is that the controls are all layed out as if the text area's are one text line high, from that the height of the panel is determined, and then the text areas expand to support word wrapping causing the controls to overlay each other without adjusting the parent panels height.
The following code has worked in past situations when displaying the form immediately, but in this case there are two forms that are toggled from a button. The first form displays fine but the second does not. I've tried a series of combinations using validate, invalidate, revalidate, and repaint with no apparent fix.
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
panelMain.removeAll();
panelMain.add(panelForm, BorderLayout.CENTER);
panelMain.revalidate();
panelMain.repaint();
}
});
I set a listener to the panel's componentResized event and what I noticed is that the initial call that paints the form has all the text area's at a height of one line of text (rest is truncated). After the method is exited the text areas are expanded and the controls improperly overlay. However, if I increase the form in any way after the initial display, the panel's resize event is called again and the layout is properly corrected.
So I am looking for either suggestions on how I can approach getting the form to layout properly when first displayed, or information on what exactly Java is doing when the componentResized event is called so that I can try to force the behavior after the first pass.
Thanks ahead of time for any information you might be able to provide.