1) I've got a collection of JTextAreas. Each concerns a separate item so I would like to maintain them as separate JTextAreas.
2) The JTextAreas are added to a JPanel using a vertical box layout. The desired effect is to have the JTextAreas positioned in a vertical column, expanding to fill the width of the JPanel.
3) The JPanel is set as the viewport view of a JScrollPane (using default scrollpane layout).
4) The JScrollPane is set as one of the children of a JSplitPane (using default split orientation).
When I move the JSplitPane divider to give the JScrollPane more space, all of the JTextAreas expand horizontally to fill the new space and re-wrap their text correctly. When I move the JSplitPane divider to give the JScrollPane less space, the JTextAreas do not compress to fit within the new horizontal constraint. Instead, a horizontal scroll bar appears on the JScrollPane. I never want the user to have to scroll horizontally. Instead I want the JTextAreas to be compressed horizontally, forcing them to expand vertically, and a vertical scroll bar can appear if necessary. Setting the JScrollPane's horizontal scroll bar policy to NEVER did not solve the problem, it just hid the horizontal scroll bar so I could not scroll to see the content even if I wanted.
It seems to me that when the JScrollPane gets wider it resizes the JPanel to fill the space but when it gets smaller it does not. Any suggestions?
SecondAttempt: setPreferredSize( new Dimension( 0,0 ) )
Result: The JTextAreas now expand and contract horizontally as I adjust the JSplitPane divider and the text re-wraps correctly in both cases. This is desirable. Unfortunately the height of each JTextArea is now fixed. What I would like is for the height to adjust along with the width so that the JTextArea has enough area to display all of its text. Unfortunately there is not a setPreferredWidth( int i ) method.
Perhaps I should be using a spring layout on the JPanel instead of a vertical box layout? I've never used a spring layout before and the Java API says it was not designed for manual use. How hard is it to use?
Thanks so much for the feed back, I will keep trying!