views:

31

answers:

2

I have a JPanel that holds a JScrollPane that holds a JPanel as such:

masterPanel.add(buttonPanel, BorderLayout.NORTH);
inner.setLayout(new BorderLayout());
inner.add(infoPanel, BorderLayout.NORTH);
inner.add(writingPanel, BorderLayout.CENTER);
beholder = new JScrollPane(inner);

masterPanel.add(beholder, BorderLayout.CENTER);

I want beholder to be a JScrollPane so that the button panel will display at all times while scrolling the beholder (inner scroll pane). This all works fine, but the problem is the panels inside of beholder do not line wrap. So I have a long line of text in infoPanel that causes a very long, undesirable horizontal scroll.

If I just change the last line to add inner instead of beholder, it works fine (wraps correctly), but then the button panel won't stay at the top when the user scrolls down.

I'm totally stuck. Basically my question is how to get the panels inside of the JScrollPane to word wrap normally.

The problem is wrapping horizontally. Even if I set beholder.setPreferredSize() to a very low x and y dimension, it will ignore the x dimension entirely even though it seems to obey the y dimension normally.

A: 

I think the Scrollable Panel will help you out.

camickr
Maybe I don't understand how to use it, but it doesn't work at all. Actually it stretches the component both ways now
tandu
Did you play with the demo? You can control stretching separately for vertical and horizontal. Maybe I don't understand the question and you didn't post a SSCCE so I can't see your exact problem.
camickr
A: 

For some reason, this problem is resolved by calling:

inner.setPreferredSize(inner.getPreferredSize());

This will cause the wrap to occur.

tandu