The Artima Developer Community
Sponsored Link

Java Answers Forum
resizing JPanel not working

2 replies on 1 page. Most recent reply: Nov 23, 2004 1:00 AM by Amol Brid

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Gibran Shah

Posts: 27
Nickname: gibby
Registered: Jun, 2004

resizing JPanel not working Posted: Nov 10, 2004 10:47 AM
Reply to this message Reply
Advertisement
Hi,

I've got a JScrollPane with a JPanel set as its view. In this JPanel, I have a set of smaller panels layed out in rows. My program allows for the user to remove existing rows or add new rows to the parent JPanel. The problem I'm encountering is that when the user adds a new row, I need to resize the parent JPanel such that all rows are visible, but calling JPanel.setSize(int,int) or JPanel.setSize(new Dimension(int,int)) doesn't seem to do anything to the size of the parent JPanel. Is there anything special that must be done to JPanels that are views for a JScrollPane in order to see changes that are made to it? For example, do I need to call repaint(), do I need to set the view again (i.e. ScrollPane.getViewport().setView(MyParentPanel);). I've tried these already, and I'm wondering if anyone has any other suggestions.

Gib


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: resizing JPanel not working Posted: Nov 13, 2004 9:18 AM
Reply to this message Reply
use setPreferredSize
public void setPreferredSize(Dimension preferredSize)

Amol Brid

Posts: 43
Nickname: amolbrid
Registered: Feb, 2004

Re: resizing JPanel not working Posted: Nov 23, 2004 1:00 AM
Reply to this message Reply
Hi,

override the validateTree() method of the parent panel and call the validate() method of all the child panels.

This should solve your problem.

Flat View: This topic has 2 replies on 1 page
Topic: Classpath problem with j2sdk142_nbide351 Previous Topic   Next Topic Topic: KODO JDO performance

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use