• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
apchar boiir
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)

 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did. The corrected code is:
 
Wolfgang Tintemann
Ranch Hand
Posts: 65
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for this very informative example.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic