File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes multiple views in swing(urgent help needed) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "multiple views in swing(urgent help needed)" Watch "multiple views in swing(urgent help needed)" New topic
Author

multiple views in swing(urgent help needed)

PMP Kannan
Greenhorn

Joined: Jan 23, 2003
Posts: 10
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
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

"kannan" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

I'm not sure why clone does that... there may be some way to work around it, but here's some code illustrating what you want to happen:


Thanks! and welcome to the JavaRanch!


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
PMP Kannan
Greenhorn

Joined: Jan 23, 2003
Posts: 10
Hello Nathan ,
thank u so much for the timely help. it's exactly what i wanted.
thanks again
i have changed my name as u have instructed. actually my name is very long. so i have shortened it.
it's actually "Palipalayam Muthusamy Palanisamy Kannan"
so i have shortened it to PMP Kannan
is it ok with the naming policy

Cheers
kannan
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You are welcome!

And yes, your new name is fine with the naming policy!

Thanks,
-Nate
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multiple views in swing(urgent help needed)