Reputation: 356
In my app, I have a class that acts as a Swing component to render a 3D window using LWJGL. When I go to run the app, I get the error from Display.create()
that Parent.isDisplayable() must be true
. I've tried looking, and most people say it happens when you call Display.create() before calling setVisible(). However, that's not the case here, and I can't seem to figure out why I'm getting the error.
My control looks like this:
public class WorldCanvas extends JPanel {
private final Canvas canvas = new Canvas();
public WorldCanvas() {
...
add(canvas, BorderLayout.CENTER);
try {
Display.setParent(canvas);
setVisible(true);
canvas.setVisible(true);
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
return;
}
}
}
It's being added directly to a JFrame, and setVisible(true) is also called on the JFrame before this is added (however this error is being generated before it can even be added, given it's in the constructor). Why am I getting this error?
Upvotes: 1
Views: 439
Reputation: 2877
You are trying to create the display in the constructor of the JPanel that holds your Canvas.
So the Canvas is not displayable because its parent, the WorldCanvas, is not displayable as it is just about to be created.
You will have to move the initialization into a method called after the constructor.
Upvotes: 1