Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a new JFrame

Tags:

java

swing

jframe

I have a main JFrame that has all kinds of panels in it for different functions and people can calculate things in them. I want to open a new JFrame when the user hits the first calculate button and serve as a Output window (Simlar to SPSS output windows if you are familiar with them).

The New JFrame will be completely separate and will have its own menu bar ... A simple JDialog is not the way to go here.

like image 809
Killerpixler Avatar asked Mar 01 '13 21:03

Killerpixler


People also ask

How do I open a JFrame from another?

It's simple you just need to instanciate a new frame object like in the following : JFrame home2 = new Home2(); // don't forget the import since it's a custom made Frame ;) home2. setVisible(true);

How do I open a JFrame in Netbeans?

In the Projects window, right-click the ContactEditor node and choose New > JFrame Form. Alternatively, you can find a JFrame form by choosing New > Other > Swing GUI Forms > JFrame Form.


1 Answers

  • can't resist, simple disagree with answers JFrame frame = new JFrame(); and frame.setVisible(true);

I want to open a new JFrame when the user hits the first calculate button and serve as a Output window (Simlar to SPSS output windows if you are familiar with them).

  • don't do that, create only two JFrames, reuse 2nd. JFrame by using getContentPane.removeAll(), for another actions from JButton

  • then all lifecycle will be only about setVisible(true) / setVisible(false)

  • change DefaultCloseOperations to HIDE_ON_CLOSE

The New JFrame will be completely separate and will have its own menu bar. A simple JDialog is not the way to go here.

  • whats wrong with JDialog, only one button in the Toolbar in compare with three buttons in JFrame, simple disagree,

Output window (Simlar to SPSS output windows if you are familiar with them).

  • use SwingWorker or Runnable#Thread (required wrap into invokeLater) for get value for JComponents placed into JDialog, if all changes are done call JDialog.setVisible(true) wrapped into invokeLater()
like image 98
mKorbel Avatar answered Oct 06 '22 01:10

mKorbel