• Post Reply Bookmark Topic Watch Topic
  • New Topic

GridBag Problem (Replacing Component)  RSS feed

 
Jerry Crothers
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class (JPanel) thats uses the gridbag layout - its a form.

One of the event handlers needs to remove a textfield and replace it with a another component (JButton). So I am writing code like this to remove the textfield:

this.remove(textfield);
this.repaint();
this.setVisible(true);

thats fine, but it won't let me create a new JButton (or any component) and put it in that cell. So then I tried to put the original textfield back:

add(textfield, gridbagconstraints);

..and it was there. Even just add(textfield) put the textfield back.

Why I can not put another component in the original cell after the textfield is removed??
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jerry Crothers
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geez after I added:

panel.revalidate();

it worked. Thats annoying. Thanks for the code sample though.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!