• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Accessing components in a componenet

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi-
Does anybody know how to gain access (and remove) a component from the layout of another component.
i.e.
class MyClass extends JFrame{
public MyClass(){
JPanel panel = new JPanel(new BorderLayout());
getContentPane().add(panel, BorderLayout.WEST);
JTextField text = new JTextField();
panel.add(text, BorderLayout.SOUTH);
panel.addMouseListener(new MyMouseListener);
}
class MyMouseListener extends MouseAdapter{
protected MyMouseListener(){...}
public void mouseEntered(MouseEvent e){
Component c = e.getSource();
/*I know want to get the component placed in panel (the source) at BorderLayout.SOUTH and remove the component and replace it with something else*/
}
}
Thanks,
Kyle
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about this?

I used the getParent() method of Component to get the parent container, and then used the remove() method of container to remove the current component... then I added a new component to that container...

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!