Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPanel Resize

843806Jul 24 2007 — edited Jul 26 2007
Hi,

I am writing a swing based application which appends rows of components to a JPanel.

The JPanel is within a JScrollPane.

Currently I have set the components up like this:

private Dimension mainPanelSize = new Dimension(780,3500);

//....

panelMain = createNewMainPanel();
		
		
panelMain.setPreferredSize(mainPanelSize);

//...........

jsp = new JScrollPane(panelMain, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jsp.setPreferredSize(new Dimension(800,690 - adjustment));

container.add(jsp);
This setup means that the main panel is a fixed size (it is quite large but you can't scroll down forever). If I remove the line setting a preferred size of panelMain, when a new row of components is added it goes off the side of the panel (the panel increases horizontally), rather than being added below (increasing vertically).

What I would like to do is set a preferred width of panelMain, but allow the height to grow when new rows are added. Is this possible?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 23 2007
Added on Jul 24 2007
10 comments
1,282 views