0

For example, I have a JButton with a set icon, name and label; How do I make a new JButton that I can add, say, to a panel?

JButton b1=new JButton();
b1.set[whatever needs to be set];
JPanel p=new JPanel();
p.add(new JButton()[that has the properties of b1]);

1 Answers1

1

Using exactly the same properties? Then you can try b1.clone(). In your case it will be p.add(b1.clone());. clone() can create a shallow copy of your object, see clone(). And check this answer for copying.

Community
  • 1
  • 1
Ran0990BK
  • 69
  • 1
  • 3