• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

multiple views in swing(urgent help needed)

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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!
 
PMP Kannan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome!

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

Thanks,
-Nate
 
reply
    Bookmark Topic Watch Topic
  • New Topic