hi,
i am trying to get multiple views of a Jpanel ( which has some components like label , textfield etc.,)which is added to a JFrame. i tried using cloning technique and i got the clonable part of the JPanel but the cloned part is not editable. it's locked. could anyone tell me how a component can be viewed in multiple editors at the same time and changes made in one editor will be reflected in all editors. Each view is identical to the others.
( for example in NETBEANS
IDE we have this functionality) in the
java editor of NetBeans IDE if we click clone view u get a new frame with the same contents and changes made in the cloned view is reflected in the main editor and vice versa.
some one pls do help me.( urgent)
thanks in advance
the code i tried to use using clonable interface is given below.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CloneFrame extends JFrame implements ActionListener {
CloneTest cloneTest = null;
CloneTest cloneTes = null;
JButton button = null;
public CloneFrame() {
cloneTest = new CloneTest();
button = new JButton("Save");
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(cloneTest, "Center");
this.getContentPane().add(button, "South");
button.addActionListener( this );
this.setSize(200,200);
this.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
CloneTest cl2 = (CloneTest)cloneTest.clone();
JFrame frm2 = new JFrame();
frm2.getContentPane().setLayout( new BorderLayout() );
frm2.setSize(100,30);
frm2.getContentPane().add(cl2, "North");
frm2.setVisible(true);
}
public static void main(
String ar[]) {
new CloneFrame();
}
}
class CloneTest extends JPanel implements Cloneable {
JButton jb;
JTextField jt;
public CloneTest() {
jb = new JButton("hello");
jt = new JTextField("hello world");
add(jb);
add(jt);
}
public Object clone() {
try {
return super.clone();
}
catch (CloneNotSupportedException e) {
throw new InternalError(e.toString());
}
}
}
cheers
Kannan
A wise man is one who forgets the faults of others, but always remembers his own