Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

start a new JFrame from an existing one, and when old JFrame closes new one does not

Thread view: 
jakester - 02 Apr 2007 23:29 GMT
I have the need to create a new JFrame from an existing one. The code
below show how I am accomplishing this task. However, when the
original JFrame closes, all JFrames created from the original JFrame
closes. Could someone please help me how to create a new JFrame so
that it runs outside the thread of the original? Thanks.

public class MyGuiForm extends JFrame implements ActionListener {

private JButton _btnNew;

public MyGuiForm() {
_btnNew = new JButton("New");
_btnNew.addActionListener(this);

this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(_btnNew);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
this.show();
}

public void actionPerformed(ActionEvent ae) {
Object source = ae.getSource();
if(null == source) return;

if(_btnNew == source) {
new MyGuiForm();
}
}

/**
* @param args
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame.setDefaultLookAndFeelDecorated(true);
new MyGuiForm();
}
});
}
}
Knute Johnson - 02 Apr 2007 23:50 GMT
> I have the need to create a new JFrame from an existing one. The code
> below show how I am accomplishing this task. However, when the
[quoted text clipped - 39 lines]
> }
> }

Your code is very difficult to read without any indentation.

You tell your program to exit when this frame is closed with this line:

> this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Take that line out and it won't do that any more.  Also you don't need
all of the 'this.' in front of methods that are part of 'this'.

Signature

Knute Johnson
email s/nospam/knute/

jakester - 03 Apr 2007 00:13 GMT
If I comment out the code
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); then I get the
intended behaviour. The problem is now the java thread does not
terminate.

I looked at the JavaDocs for the options on setDefaultCloseOperation
and it turns out JFrame.DISPOSE_ON_CLOSE would probably help me out.
So I uncommented the line above and did
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); and everything
works!

Thank you both.

On Apr 2, 6:50 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
> > I have the need to create a new JFrame from an existing one. The code
> > below show how I am accomplishing this task. However, when the
[quoted text clipped - 53 lines]
> Knute Johnson
> email s/nospam/knute/
SadRed - 02 Apr 2007 23:54 GMT
> I have the need to create a new JFrame from an existing one. The code
> below show how I am accomplishing this task. However, when the
[quoted text clipped - 42 lines]
> }
> }

> this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Use other value. See API doc.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.