I want to copy my private jlabel object to a new jlabel object and make the new one public. Idea is to allow anyone to access jlabel's properties but not to allow make any changes that will be displayed on the original interface. Below code doesnt work as it simply copies the reference of the original object.
public javax.swing.JLabel getCopyOfLabel(int labelno) {
javax.swing.JLabel newlbl = new javax.swing.JLabel();
if (labelno == 0) {
newlbl = lbl_0_original;
return newlbl;
} else if (labelno == 1) {
newlbl = lbl_1_original;
return newlbl;
} else {
newlbl = lbl_2_original;
return newlbl;
}
}
How can I do it the way I want? Can I use clone() on this?
Thank You