Hello i want to set the size of JFrame, when the user changes the screen resolution.
this.setSize(myWidth, myHeight);
This is working fine and the window gets smaller/bigger. But if I set the Extended State, it will not affect. I can still see the Menu Bar.
this.setExtendedState(Frame.MAXIMIZED_BOTH);
this.setUndecorated(true);
Must I call a function, when I'm changing the ExtendedSate and the JFrame is running? In the initialisation, ExtendedState is working fine without calling a function, which rebuild or reload the JFrame.
I have found no really simple native way, without a lib.
Related
I am developing a Java Swing-based application with different perspectives. For the "main menu" perspective I do not want the window (JFrame) to be decorated, while in other perspective I do want the window to be decorated. In other words, I need want to change the decoration attribute dynamically.
I have tried to use setUndecorated(false) and setUndecorated(true), but I seems I can only set this once, before actually showing the window.
Is there a way to achieve this?
From the javadoc:
Disables or enables decorations for this frame. This method can only be called while the frame is not displayable.
Therefore, once the JFrame is packed and/or displayed, you can no longer change that value. If you want to change the undecorated state of a JFrame you will need to dispose() it first, then change the state and eventually make it visible again.
After all, I had to take a different approach.
The former solution did work, as I stated in my last comment.
However, it was showing the default LAF window decoration, while I was using a different LAF.
So the result was graphically inconsistent with the rest of the LAF. Finally, I came with the right solution, I used setUndecorate(true) for my frame. Then, when I had to change my perspective to one using decorations I simply had to use the following code
contentPane.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
And when I had to revert to the non decorate perspective, I use
contentPane.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
This approach didn't need to dispose the window and show it again (which actually produced a brief but still visible hide/show of the window)
I have created a java program in which i have used the setContentPane() method on a JFrame. My problem is that the frame does not get updated by the new panel immediately but gets updated upon resizing the frame.
In my program the size of the JFrame is 600,600.
To temporarily avoid this problem, after the setContentPane() method , I have applied a set of 2 statements:-
Frame.setSize(601,601);
Frame.setSize(600,600);
This resizes the frame and brings it back to its original size without showing much change to the user. This is working good and the panel is getting updated.
My question is, am I making any mistake and there is some other way to do it? Or I can continue using this trick? Please answer if there is any other(right) way to do it.
I am making an application where I need to have a Preferences JFrame which can open another JFrame for further preferences of a certain type. Though I do not want the further preferences JFrame to be able to have more than one instance open at the same time.
I have tried using the .isActive() method but that always no matter what happens reports that the variable used to make the new instance of the JFrame is equal to null, which it has been initially set to when it was initialised.
So what is the best way of actually checking if a certain JFrame already has an instance in existence? Is it to get it to write to a variable when it launches and when it quits? If so, how would you get it to write to a variable when someone pressed the x button, and what if it crashed and closed not through the standard means?
Or is there another way of doing it like getting the isActive() method to work or another method that would do better?
What you should do is to make the JFrame a modal JDialog. Instead of opening a JFrame, you open a JDialog. You pass the other settings window as the parent and pass true for modal. This will prevent any action in the other settings window as long as this modal dialog is open.
Thats what a lot/almost every program uses. Have you ever noticed that, when you open a settings window and try to click on the main window, the settings window pops back on top and blinks for a second? Thats what the modal dialog does.
Why don't you just avoid creating a new JFrame at all? Just make one earlier in your execution and make it visible when you need it and hide it when you temporarily don't need it anymore. Trying to make an already visible JFrame visible or hide a hidden JFrame shouldn't do anything.
I have JFrame, that is setUndecorated(true) and inside it's content pane there is a LwjglCanvas a libgdx application rendering it's things.
I need at some point, do setUndecorated(false). But is seems to be impossible.
the decorated state cannot be changed once JFrame has been displayed, the only way to do it is to either create new JFrame, or dispose the existing one, and pack it back. Both solutions are terrible for me, because both will eventually notify LwjglCanvas to stop, and once stopped it cannot be started again.
I tried overwriting it's stop method, but it still get's messed up somehow.
Why do I need this?
I am trying to make a loading splash screen for libGDX desktop app, with a progress bar in it, that should display progress of my desktop app loading it's resources in opengl context. Splash screen has to be undecorated window, and when all loaded app itself should show, maximized and decorated.
Approaches that do not work:
Use one JFrame, and switch between decorated modes.
Try to move Lwjgl canvas from one JFrame to another
Use 2 separate Lwjgl canvases (cannot be done, because only one Al
context can be inited at a time)
How do I do this?
I am developing a Java Swing-based application with different perspectives. For the "main menu" perspective I do not want the window (JFrame) to be decorated, while in other perspective I do want the window to be decorated. In other words, I need want to change the decoration attribute dynamically.
I have tried to use setUndecorated(false) and setUndecorated(true), but I seems I can only set this once, before actually showing the window.
Is there a way to achieve this?
From the javadoc:
Disables or enables decorations for this frame. This method can only be called while the frame is not displayable.
Therefore, once the JFrame is packed and/or displayed, you can no longer change that value. If you want to change the undecorated state of a JFrame you will need to dispose() it first, then change the state and eventually make it visible again.
After all, I had to take a different approach.
The former solution did work, as I stated in my last comment.
However, it was showing the default LAF window decoration, while I was using a different LAF.
So the result was graphically inconsistent with the rest of the LAF. Finally, I came with the right solution, I used setUndecorate(true) for my frame. Then, when I had to change my perspective to one using decorations I simply had to use the following code
contentPane.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
And when I had to revert to the non decorate perspective, I use
contentPane.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
This approach didn't need to dispose the window and show it again (which actually produced a brief but still visible hide/show of the window)