Resizing JPanel embedded in JScrollPane

Hello

Would someone please help me out ?

my GUI application has a JPanel1 that is embedded in a JScrollPane. The JScrollPane is then embedded in a JPanel2. Lastly the JPanel2 is embedded in a JFrame.

I need to write a piece of code to resize JPanel1 every time the window of my GUI is resized.

Is this doable ?

Also Jpanel1 and 2, and the JScrollPane are in the same class. The JFrame is a different class.

Is possible to add a changelistener to the JScrollPane ?

Thank you in advance.

[534 byte] By [va97a] at [2007-11-26 18:03:19]
# 1

You miss the point of using a scroll pane. The panel added to the scroll pane is generally of a fixed size. So if the size of the scroll pane changes because the frame is resized, then the scrollbars will appear or disappear automatically. What is the point of resizing the panel to match the size of the frame? Why is it added to a scroll pane?

Anyway, if these is what you really want, then add a ComponentListener to the JFrame and resize the panel in the componentResized(..) method.

camickra at 2007-7-9 5:33:28 > top of Java-index,Desktop,Core GUI APIs...
# 2

Currently, the panel is of a fixed size. It was added to the JScrollPane b/c some texts were too long so when we shrink the frame as you said, the scrollbars appear automatically, which is what we want.

But the leader of the project said he wanted the panel resized (so that the texts will shrink) as the frame is also resized, which will disqualify the purpose of the scrollbars, b/c we can't have both. IF the panel is to be resized, then we don't need the scrollPane, but he does.

It is all trying to fulfill user's requirements.

Thank you camickr.

va97a at 2007-7-9 5:33:28 > top of Java-index,Desktop,Core GUI APIs...
# 3

Hi camickr

May be you can help me out ?

in the panel(uses GridLayout), there are JLabels that are using html tags to word wrap the texts when they are too long.

For example:

text1text2text3text4 (line1)

text5text6text7text8 (line 2)

When the user shrinks the window, the word wrap works until line 1 and line 2 overlaps, then we can't read both lines.

Instead of having them overlap, is there a way to make the code word wraps the texts until the words occupy one line each, like the one below ?

text1

text2

text3

text4

text5

etc...

va97a at 2007-7-9 5:33:28 > top of Java-index,Desktop,Core GUI APIs...