• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

GridBag Problem (Replacing Component)

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Jerry Crothers
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Geez after I added:

panel.revalidate();

it worked. Thats annoying. Thanks for the code sample though.
 
I love a good mentalist. And so does this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic