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.
- can't resist, simple disagree with answers
JFrame frame = new JFrame(); andframe.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.
JFrameby usinggetContentPane.removeAll(), for another actions fromJButtonthen all lifecycle will be only about
setVisible(true)/setVisible(false)change
DefaultCloseOperationstoHIDE_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 theToolbarin compare with three buttons inJFrame, simple disagree,
Output window (Simlar to SPSS output windows if you are familiar with them).
- use
SwingWorkerorRunnable#Thread(required wrap intoinvokeLater) for get value for JComponents placed into JDialog, if all changes are done callJDialog.setVisible(true)wrapped intoinvokeLater()
JFrame newFrame = new JFrame();
newFrame.setVisible(true);
I maybe mis understanding your question but
JFrame frame = new JFrame();
frame.setVisible(true);
来源:https://stackoverflow.com/questions/15167404/open-a-new-jframe