Open a new JFrame

I have a main JFrame in which there are all kinds of panels for different functions, and people can calculate things in them. I want to open a new JFrame when the user clicks on the first calculation button and serves as an output window (Simlar for SPSS output windows if you are familiar with them). A.

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

+7
source share
4 answers
  • can not resist, just do not agree with the answers JFrame frame = new JFrame( ); and frame.setVisible(true);

I want to open a new JFrame when the user types the first calculation and use it as the output window (Simlar for SPSS output windows, if you are familiar with them).

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

  • then the whole life cycle will be only around setVisible(true) / setVisible(false)

  • change DefaultCloseOperations to HIDE_ON_CLOSE

The new JFrame will be fully shared and will have its own bar menu. A simple JDialog is not the way to go.

  • What is wrong with JDialog , only one button in the Toolbar compared to the three buttons in the JFrame , just do not agree,

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

  • use SwingWorker or Runnable#Thread (you need to wrap it in invokeLater ) to get the value for the JComponents placed in JDialog, if all changes are completed, the call to JDialog.setVisible(true) wrapped in invokeLater()
+9
source
 JFrame newFrame = new JFrame(); newFrame.setVisible(true); 
+10
source

Never use more than one JFrame in a Swing application. Use JDialog for additional windows.

See Using Multiple JFrames, Good / Bad Practice? .

+5
source

I may misunderstand your question, but

 JFrame frame = new JFrame(); frame.setVisible(true); 
+4
source

All Articles