Change undecorated state of swing JFrame with LwjglCanvas inside - java

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?

Related

Simulate mouse click/scroll/etc on swing without using Robot

I want to simulate basic input for a swing application. The whole thing runs headless and doesn't even have a JFrame. I just render all components from the JPanel using the draw() method on a Image (If you want to know why: The Image gets rendered on minecraft maps where users then should be able to interact). I want to execute click or scroll actions on the panel like it would come from regular user.
I know that I can simulate a Button click using doClick() but this doesn't work for components like checkboxes. I also tried using dispatchEvent() but that didn't fire the animations or on some components even threw a HeadlessException.

How to display LWJGL window and swing window at same time?

I want to do the following:
I've got a LWJGL display, and a running game loop. I did not explicitly create a thread for this. It just runs on the thread it takes. (the thread it is created in?)
Now I want to create a Swing JFrame, but of course this is not that simple.
Because when I tried this, the swing window blocks. It just doesn't update and it won't close, and this behaviour is expected.
I tried to create a new thread and put the JFrame in that new thread, but also this doesn't change the behavior.
I really know swing should be executed in the Event Dispatch Thread, but I don't know how to solve this problem. I also tried a lot with SwingUtils.invokeLater, but actually this has very little to do with the problem.
What can I do to have a LWJGL display and a working JFrame at the same time?
I want that JFrame to display generated BufferedImages to debug. The BufferedImages are used for creating textures. I don't want to output that debugging data to disk, and just want to display the images in a JFrame.

Java Swing repaint & threads

Context: in my Java Swing app I have a chart (using JFreeChart) and when the user clicks on a datapoint on it, it opens a specific flash animation in a JDialog (flash played using DJNativeSwing).
Problem: when the flash animation starts playing, for some reason the background chart in the main window decides to refresh (calls its paintComponent()) and, as the chart is fairly heavy, this takes ~4 seconds during which the flash animation freezes.
I am thus looking for the most elegant / simplest solution to avoid the flash freeze. So far, I could imagine:
Find out why paintComponent() is called and avoid this
Open the JDialog (or child window without modal behavior) on a different thread
What would be the best approach and, most importantly, how to do it?

Update JFrame size and extended State

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.

How to create multiple screens in Java?

I have been playing around with trying to get a menu screen for my game. I have only been able to figure out how to paint a new Screen on top of an existing one; meaning that the actual game is still running behind the title screen. I don't need actual code but just a description of how I would go about this.
One way to display a menu would by by using a JDialog outside of your main application window. Take a look at the How to Make Dialogs tutorial for more information.
Another possibility would be to use JInternalFrame for your game and menu so they can be wrapped in a larger application frame. These are explained nicely in How to Use Internal Frames

Categories