View Single Post
  #2 (permalink)  
Old 06-19-2009, 01:22 AM
hardwired's Avatar
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
Save a reference to them that you can use later to refer to them.
Code:
class Pseudo {
    JTextField textField;
    JButton button = new JButton("hi");

    private void buildUI() {
        testField = new JTextField(12);
        JPanel panel = new JPanel(someLayout);
        panel.add(textField);
        panel.add(button);
    }
}
Or you can use the Container methods like getComponents to access them.
Code:
Component[] c = panel.getComponents();
for(int i = 0; i < c.length; i++) {
    System.out.println(c[i].getClass().getSimpleName());
}
Reply With Quote