Java: Set back the same JFrame [duplicate] - java

This question already has answers here:
How to go back to a JFrames in Java
(3 answers)
Closed 7 years ago.
When I open a new JFrame, I set the old one as false:
ExampleJFrame.this.setVisible(false);
ExampleNewJframe newOne = ExampleNewJframe();
newOne.setVisible(true);
But If I am in newOne, how do I get back to the original Frame without creating a new as I did above?

The best solution: don't go swapping JFrames; that's can be a rough design that can annoy users. Instead swap JPanel "views" using a CardLayout as per The Use of Multiple JFrames, Good/Bad Practice?.

Related

How to create loading screen for Java Swing? [duplicate]

This question already has answers here:
Swing application initialization and loading screen approach
(2 answers)
Making a loading screen in netbeans
(2 answers)
Closed 2 years ago.
I have a Java Swing program that has a lot of components and I want to implement a waiting animation that can be called on will (if it can be packaged all into one method call - not for just when the program begins). The idea is that I have two images that swoop in PowerPoint style --> wait for the components to be done --> the two images swoop out. I plan to do the animation for the two images in Java Swing (that is incrementing their x and y positions over time). Any ideas how I can go about this? I was thinking that I need a SwingWorker but I'm not very experienced with those. Is it even possible to know when Swing is done processing and painting all the components? Thank you.

Use main method in JFrame class or just call the JFrame? [duplicate]

This question already has answers here:
Java/Swing GUI best practices (from a code standpoint) [closed]
(2 answers)
Closed 4 years ago.
So what's the best practice, use a JFrame as the one that contains the main method, or just create a main class, and call the JFrame?
I'm not sure it matters at all, but i'm wondering if there are any advantages using the main in JFrame class or not?
I personally try to keep the main method in its own class because maybe you want to do more than just start the JFrame at startup.
But that really depends on what you want to do, if you only want to start the JFrame then the main method in the JFrame is also good.
You may also want to have a look at this post

How do I set a title to a jframe? [duplicate]

This question already has answers here:
Changing the JFrame title
(4 answers)
Closed 4 years ago.
I am a beginner and I designed a frame but I didn't do it manually. Instead I used the design tool in Netbeans. I am trying to set a title with the following code in my main method but I still wont get it.
...
/* Create and display the form */
java.awt.EventQueue.invokeLater(() -> {
new QueuesFrame().setVisible(true);
QueuesFrame.SetTitle("myCase senario");
});
}
Java is case sensitive, so SetTitle should be setTitle and you need to perform the operation on an instance of the frame
QueuesFrame frame = new QueuesFrame();
frame.setTitle("myCase senario");
//frame.pack();
//frame.setLocationRelativeTo(null);
frame.setVisible(true)
Instead I used the design tool in Netbeans
If you interested in become a decent developer, I would strongly recommend avoiding the form editors until you have a better grasp of how the Swing (or even JavaFX) APIs actually work - it will give you a better baseline of skills and reduce the mess that form editors get you into

Is there a way to tell if a JFrame is "Maximised" (MS Windows) [duplicate]

This question already has answers here:
JFrame in full screen Java
(14 answers)
Closed 9 years ago.
I've been Java applications on OS X, and haven't had the opportunity to fully test in different places.
There are 2 different JFrames. The second is loaded exactly in place of the first one, and as such needs to have its size and location set to the same as the first.
This works fine, but I noticed a lot of Windows users seem to maximise the first window. When the second JFrame loads, it has the same size, but is not "maximised".
Maximised windows in the MS Windows world have a slightly different state and are treated differently by the OS.
How can I tell if a JFrame is Maximised, and how can I maximise one myself?
frame.setExtendedState( f.getExtendedState()|JFrame.MAXIMIZED_BOTH );

swing: make a window never lose focus [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
“Always on Top” Windows with Java
I am using JFrames
I have a window(ex-Accounts) which gets called from a button in MainMenu.
As long as Accounts is opened i want to forbid the user from accessing MainMenu(which should be visible) unless he closes the Accounts window.
This means that you need your window to be modal. JDialog can be modal, you can either mention this in the constructor like this:
new JDialog(parent, true);
or starting with Java 1.6, you can set the ModalityType:
new JDialog(parent, modalityType);

Categories