Handle components in a container

0

I added a frame with multiple components to a container . In another class I add the container data to jPanel. In this class, is there any way I can access the components of this container ?

Container ct3 = new Container();
ct3 = this.getContentPane();

The point is that I've added all the frame components to container , but when I show those components in another class, I'd like some components not to be shown. In the other class I have this:

painelPrincipalConfMainMenu.add(ConfUtilizador.ct3.getComponent(0));

Is there any way to do this?

    
asked by anonymous 05.12.2014 / 13:55

1 answer

1

Test like this:

Code:

    Component[] components = ConfUtilizador.ct3.getContentPane().getComponents();

    for (int i = 0; i < components.length; ++i) {
        if ((components[i] instanceof JButton)) {
            System.out.println(" um botao");
            JButton button = components[i];
            if(button.getttext().equals("ok"))
                   button.setVisivel(false);

        }else if ((components[i] instanceof JLabel)){
            System.out.println(" uma label");
            JLabel label= components[i];
            if(label.getttext().equals("nome"))
                   label.setVisivel(false);
        }else {
            System.out.println(" outro componente qualquer");
          }
    }
    
05.12.2014 / 14:25