Killerpixler
Killerpixler

Reputation: 4050

Open a new 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.

Upvotes: 10

Views: 67850

Answers (5)

HaiCNCS
HaiCNCS

Reputation: 5

I used code JFrame frame = new JFrame(); frame.setVisible(true);. This block of code just do empty window.

Upvotes: 0

mKorbel
mKorbel

Reputation: 109815

  • 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()

Upvotes: 13

Eng.Fouad
Eng.Fouad

Reputation: 117589

Never use more than one JFrame within a Swing application. Use JDialog for extra windows instead.

See The Use of Multiple JFrames, Good/Bad Practice?.

Upvotes: 5

clicky
clicky

Reputation: 865

I maybe mis understanding your question but

JFrame frame = new JFrame();
frame.setVisible(true);

Upvotes: 4

SLaks
SLaks

Reputation: 887345

JFrame newFrame = new JFrame();
newFrame.setVisible(true);

Upvotes: 11

Related Questions