Updating Swing compos during Jogl's diplay

  1. My game loads ands binds textures inside the display(GLDrawable …) method. While it works fine, I’d like to update some of the Swing components laying next to Jogl’s GLCanvas, for example a Progress bar or such.
    However, these Swing components aren’t being updated when I do some JLabelXy.setText(…) inside the display method.
    I added some Thread.yield and .sleep commands inside the display method to maybe give some time to the Swing thread, but with no effect.

How do you solve such problems, please?

Some details. In the game there’s the typcial small game loop in the main thread:
while (ingame) {
do Sim etc
do check key’s variables / mouse pos
GLmyCanvas.display()
}

The key and mouse listeners on the GLcanvas are being called automatically in the seperate Swing thread and just store keys etc in variables.
Probably it shouldn’t matter but the app’s runing on an ATI 3d card currently (I say this because there’s some workaround messaged being printed by Jogl).

  1. Part two of the question: Even if I didn’t use Swing components to display the progress but OpenGL elements, I’d have the problem that loading textures inside the display method stops anything from being rendered during that (long) cycle. How do you solve this?
    (Maybe just load and bind one texture at once and delay the others to the next display call)
  1. You have to modify Swing GUIs only from within the Event-Thread (http://java.sun.com/developer/technicalArticles/Threads/swing/?frontpage-jdc). Just use SwingUtilities (http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/SwingUtilities.html) and call invokeAndWait() or invokeLater() to update your components.

  2. I don’t know if there is a better solution, but yes, I think you have to implement some kind of scheduler to do such kind of work in small chunks.

[quote]1) You have to modify Swing GUIs only from within the Event-Thread
[/quote]
Thanks for the reminder.

[quote]2) I don’t know if there is a better solution, but yes, I think you have to implement some kind of scheduler to do such kind of work in small chunks.
[/quote]
I did: just bind one texture each display call. It’s working much better now.
At the start of a new level I think I’ll have to draw all needed textures once in some invisible corner, so that they’ll all get bound…