File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

multiple views in swing(urgent help needed)

PMP Kannan

Joined: Jan 23, 2003
Posts: 10
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 );

public void actionPerformed(ActionEvent ae) {
CloneTest cl2 = (CloneTest)cloneTest.clone();
JFrame frm2 = new JFrame();
frm2.getContentPane().setLayout( new BorderLayout() );
frm2.getContentPane().add(cl2, "North");
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");

public Object clone() {
try {
return super.clone();
catch (CloneNotSupportedException e) {
throw new InternalError(e.toString());

A wise man is one who forgets the faults of others, but always remembers his own
Nathan Pruett

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!

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

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

Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

You are welcome!

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

I agree. Here's the link:
subject: multiple views in swing(urgent help needed)
It's not a secret anymore!