I have a javax.swing.JButton
which I have created to sign out. How can I get an exact copy(duplicate) of the button to another JFrame
?
private JButton signOut;
public JButton getBtn(){
//Any idea?
}
return signOut;
is not an option, because then it will screw the home page when I call setBounds()
or setVisible()
of signOut
.
Do I have to create a new Object of the class with the button to get only this component? Or is there another solution?
Abstract the building of that button into some sort of factory or function. This way, you don't have to constantly manually reconfigure the button nor do you have to worry about copying / cloning (which can get very messy)
public JButton createButton(string caption) {
//Create button here
}