aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes can't add to JPanel after removeAll() is triggered by another swing component Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "can Watch "can New topic
Author

can't add to JPanel after removeAll() is triggered by another swing component

apchar boiir
Greenhorn

Joined: Sep 07, 2004
Posts: 18
Consider the bit of code below. It's a much simplified version of my real app.
In jPanel1 is a single label. In jPanel2 is a single button.
The button in jPanel2 is supposed to wipe clear (with removeAll()) jPanel1 and add a new label in place of the old one. What actually happens is that after the first button press, jPanel1 is indeed cleared by the removeAll() method but the new label can't be added (or rather it can be added but won't show.) I can hard code the removal & addition back and forth all day & it works fine. It's just when I use a swing component like JButton or JComboBox that it doesn't work. Why?? Is this a thread thing? (I know I can just change the text of the label but the real app is much more complicated.)

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

apchar, we don't have too many rules here, but we do ask that you BeForthrightWhenCrossPostingToOtherSites.

http://forums.oracle.com/forums/thread.jspa?threadID=2248016
http://www.java-forums.org/awt-swing/46092-cant-add-jpanel-after-removeall-triggered-another-swing-component.html
http://www.javaprogrammingforums.com/awt-java-swing/9666-cant-add-jpanel-after-removeall-triggered-another-swing-component.html


luck, db
There are no new questions, but there may be new answers.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2203
    
    7
So I see you got an answer on another forum.

Are you now going to update your other postings to indicate you have an answer so people don't waste time ansswering a question that has already been answered???
apchar boiir
Greenhorn

Joined: Sep 07, 2004
Posts: 18
I did. The corrected code is:
Wolfgang Tintemann
Ranch Hand

Joined: Sep 11, 2010
Posts: 65

Thank you for this very informative example.


Time isn't Money, Money is Time.
The man who works looses his time ( spanish proverb )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can't add to JPanel after removeAll() is triggered by another swing component