Hello Guest

Using swing popups without freezing thread?

  • 2 Replies
  • 3778 Views
Using swing popups without freezing thread?
« on: May 19, 2015, 00:56:58 »
I'm trying to make a level editor, and I'm using lwjgl2 to render on a canvas. When I try to use JFileChooser, the window and filechooser freeze when I close the filechooser window. I tried putting the fileChooser.showOpenDialogue() in a new thread, but it didn't do anything to fix the problem. Is there a way to put them in separate threads so they don't conflict?

*

Offline Cornix

  • *****
  • 488
Re: Using swing popups without freezing thread?
« Reply #1 on: May 19, 2015, 10:12:56 »
All Swing components / windows / dialogs have to be run on the Event Dispatcher Thread (EDT). First of all, you should make sure that you open your JFileChooser on the EDT and not on any other thread.
Another problem comes with MacOS, there are some crazy rules on mac that AWT stuff (Swing is build on top of AWT) has to always run on the first thread within the JVM. The same applies to GLFW (which is used in LWJGL 3) which also has to be run on the first thread within the JVM. Now, I dont know exactly what LWJGL2 is using but if you are on a mac there could be the same problem with the first thread being occupied by something else.

If neither of the above points is the source of the problem you should show us the relevant pieces of code that lead to this problem of yours. I have no problem using LWJGL2 or LWJGL3 together with Swing on my windows machine.

Re: Using swing popups without freezing thread?
« Reply #2 on: May 19, 2015, 14:46:07 »
I'm not on mac, I have windows 7. And before I did the showOpenDialogue using SwingUtilities.isEventDispatchThread returns true, so I don't know why it's still freezing the main thread.