How do I change a component that is called in a different class?

for example i have added a button on a jframe then called the frame, then in another class how can i change the setVisibilty of the button that was called in the other class?

By creating a small public method in the first class to do that eg
public void makeButtonVisible() { myButton.setVisible(true); }
then calling that public method from the other class.
This keeps the implementation of the GUI private to the first class, and just exposes a public method that can be called safely from outside.

there are 3 ways

1/ set JComponent public static, beginers way, in this case you can directly call className.myComponent#someMethods (all methods as in original class)
but combined JComponents sometimes refuse to work correctly, for this reasons there are exist

2/ set Constuctor for JCompoents between clasess, then you can modified that as you expected

3/ or sometimes (swith betweens JPanels) should be usefull just call getParent(I'm love that because never ever disappoint me)


4/ with getParent method you can get collection Component[] components SomeParent.getComponents from parent, but this option isn't good for newbee and nonDynamic Container, its for pre/post testing purposes,

cool thanks that really helped me.