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!

Want JPanel to automatically resize

843805Mar 29 2007 — edited Mar 30 2007
Hi all,

I have a JPanel using FlowLayout, to which I add new JComponents during my program's run. When the JComponents run out of room horizontally, they place themselves on the next row down, as they ought to. However, the JPanel does not expand to fit them -- instead they disappear below the edge of the JPanel.

My addItem() method is very simple:
private someMethod(){
        ...
       itemContainer = new JPanel();
       itemContainer.setLayout(new FlowLayout());
       itemContainer.setBorder(BorderFactory.createLineBorder(Color.black));
}

private void addItem(myObject item){
	JComponent childPanel = myItem.getJComponent();
	itemContainer.add(childPanel);
}
The items get added fine, but I want the JPanel to expand vertically to see them all when they overflow (and I'd prefer not to use a scollbar).

Any thoughts would be greatly appreciated!
Thanks,
Sam
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 27 2007
Added on Mar 29 2007
7 comments
1,753 views