aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes swing graphics newbie question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "swing graphics newbie question" Watch "swing graphics newbie question" New topic
Author

swing graphics newbie question

J R Hatch
Greenhorn

Joined: Sep 07, 2011
Posts: 26
So I've put some JPanels with BoxLayouts in a JPanel with a BoxLayout (as the contentpane in a JFrame), and the inner JPanels contain JLabels and JButtons which are changed from time to time. (Yes. Yo Dawg! We heard you liked BoxLayouts, so we put some JPanels in your JPanel so you could BoxLayout while you BoxLayout. Indeed.)

When these buttons and labels are added to or removed from their home panels, I call repaint on the big panel containing all of it, so that the updates are updated.

Sometimes this works and sometimes it doesn't. I'll click on a button which is supposed to make one of the panels display 5 labels with icons, and only 4 of them display. The wonky thing is that if I resize the window (by grabbing the corner with my mouse and moving it just a little), the changes *always* display correctly.

Is there an easy answer from that description to what I am doing wrong?

I'd post the code, but it's awfully long and I don't know where the important part is. I will post the code if this is not an easily diagnosed newbieproblem.

Y
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
When you add/remove components from a panel the general code should be:



If you are repacing all the components then you should be using a CardLayout.
J R Hatch
Greenhorn

Joined: Sep 07, 2011
Posts: 26
Rob Camick wrote:When you add/remove components from a panel the general code should be:



If you are repacing all the components then you should be using a CardLayout.


And you nailed it!

Thanks!

I know about cardlayout, and since I'm actually displaying cards for a solitaire game, from the name one might think it would be appropriate (and it is for some parts), but (for example) one panel contains the player's hand of cards which usually has 5 cards, but which sometimes has fewer, and which cards they are change regularly. So cardlayout (unless I misunderstand it) would not work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: swing graphics newbie question