Display.create() fails when I try to use it in combination with setParent()

Started by bartvbl, November 19, 2011, 01:48:52

Previous topic - Next topic


So I have made a little main menu in swing, and when starting the game, I would like the same window to hold a Canvas instance, used as parent for LWJGL.
Here is my code for setting up the window:

JFrame frame = new JFrame("Puzzler");
Canvas canvas = new Canvas();
frame.setSize(640, 480);

Next, I create the JPanel class that draws and handles the main menu:

this.mainMenuPanel = new MainMenuPanel(this.main);
this.jframe.setSize(500, 170);

This all works. Main menu shows up nicely, behaves as it should.
When it is finished, it calls a final function to add the canvas to the main jframe:

JPanel container = new JPanel(new BorderLayout());
container.add(canvas, BorderLayout.CENTER);
this.mainMenuPanel = null; //mark for garbage collection
this.jframe.setSize(640, 480);

There is something in this function that causes the error when I finally call Display.create(); with the canvas as parent:

org.lwjgl.LWJGLException: Parent.isDisplayable() must be true

Can anyone help me further? Thanks in advance :)


It looks like your trying to create the Display before the Canvas is even visible. Look at the basic applet example to see how the problem is fixed using addNotify/removeNotify.


I looked at that, but it didn't get me any further; in both cases I get a screen that only contains the original sized viewPort, running the game perfectly. However, the screen does not handle resize updates. Neither does it want to close.
I have moved the main loop in yet another thread, with the hypothesis that java's event handling got stuck in my main loop, but this did not fix the problem; it resulted in the exact same problem.
Basically, I can get a responding JFrame containing a Canvas that responds to resizing events.
Until I create the display. It just hangs after that.

Let me just restate the question in another way; has anyone here used some swing components to launch LWJGL using the same window (as in; a similar way as I have)? Or does there exist code where the two are used in conjunction with each other?

Edit (2)
I solved the problem. As it turned out I was calling run() on my main thread from the java awt event thread instead of start(), causing the java awt thread to execute my main loop. It works flawlessly now. Silly, silly, me.