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

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.

Related

Change undecorated state of swing JFrame with LwjglCanvas inside

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?

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?

The proper way to change content in a Java GUI application (not creating a new window each time)?

I need to make a Java desktop application for a client and the last time I did Java it was 2 years ago and a little odd.
My main query is regarding navigation between GUI.
In the past, I would just create a new JForm (JFrame maybe?) whenever a button was pressed and a new GUI form/window would open up.
This time, I'd like the GUI to be inside one JForm/JFrame with just the inner content changing, how most applications look when you press a button.
I assume this is done by putting all of my GUI elements in JPanels, and deleting/creating them when buttons are pressed on the same JForm?
If not how do I do it properly?
I'll also be using Netbeans GUI editor, if anyone has a better alternative for a Java GUI builder/IDE, let me know.
Thanks!
The simplest approach would be to use a CardLayout
This will allow you to add multiple components to the UI and control which one is actively visible
Another approach could be to create menus and menuItem and having multiple JFrames now you can get the same JFrame to be displayed whenever you click the same menuItme button. This way You can minimize the creation of JFrames.

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

java JFrame setSize

I am loading a JFrame showing the company logo and credits etc before starting the main application. I am having some problems. Fist of all, the size of my new JFrame can never be set. The JFrame looked fine when I previewed it under netBean but came out smaller every time. I tried to do it with a new constructor and setSize(), but still not working. Second, the JFrame has been loaded very slowly. No images and everything could be loaded and the JFrame stays blank for at least five seconds, really kind of annoying. Do it have anything to do with where I put the image files?
Thanks alot.
I am loading a JFrame showing the company logo and credits etc before starting the main application. I am having some problems. Fist of all, the size of my new JFrame can never be set. The JFrame looked fine when I previewed it under netBean but came out smaller every time. I tried to do it with a new constructor and setSize(), but still not working.
It is very difficult to suss out what is wrong without seeing your code, but having said that, your comment about this being a NetBeans-generated GUI suggests that the code will be very large and hard to read and interpret. It is for this and many other reasons that I am not a fan of using NetBeans to generate GUI's, especially for newbies who are just learning how to use Swing. I suggest that you write out your GUI code by hand with some user-friendly layout managers, nested by nesting JPanels if necessary. If you do it this way, you'll have some greater flexibility and control in the construction of your GUI, and you'll also have readable and debuggable code that you can post here for our assessment and help should it not work out right for you.
Second, the JFrame has been loaded very slowly. No images and everything could be loaded and the JFrame stays blank for at least five seconds, really kind of annoying. Do it have anything to do with where I put the image files? Thanks alot.
This sounds like a threading issue. I'd just load the images for the intro GUI first, then show the intro window, and then in a background thread, load any other resources that the program needs.
Having said all this, you probably want to look into using Java's own splash screen as this may do all that you're trying to cobble together on your own. The tutorials can help you with this (please click on link above or here).
Much unclear question description though I want to point some tips...
Do it have anything to do with where I put the image files?
If you mean your JFrame title image so you can use its setIconImage() method
Fist of all, the size of my new JFrame can never be set.
It is quite strange :( because you can always write code like a
JFrame aFrame=new JFrame();
aFrame.setSize(x,y);
... to control your frame scale
Second, the JFrame has been loaded very slowly. No images and
everything could be loaded and the JFrame stays blank for at least
five seconds
It may be caused by single thread overloaded but still to analyze the problem show the main class code or its exceptions stack trace
previewed it under netBean but came out smaller every time
what component do you use to paint your logo? And how do you paint it? Show the snippet
You can set the size by right click on the jFrame and
Set Default size
(netbeans design view)
I hope this is what you want
this may be useful for you?
JPanel aa = new JPanel(new GridBagLayout());
aa.setMaximumSize(new Dimension(500,500));
aa.setMinimumSize(new Dimension(490,490));
aa.setBorder(BorderFactory.createLineBorder(Color.black));
I opened the properties dialog for my JFrame and set "minimum size" field to [500,500] but that did not work.
What did work for me was selecting the "..." button at the right of the "minimum size" property. In the "JFrame Mininumsize" dialog as follows:
set dropdown (Set forms minimum size property using: ) = "Custom Code"
set code in (Form.setMinimumSize( ) ) = "new Dimensiom(500,500)"

Categories