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();
canvas.addComponentListener(adapter);
canvas.setIgnoreRepaint(true);
frame.setSize(640, 480);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
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.jframe.getContentPane().add(mainMenuPanel);
this.jframe.validate();
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.jframe.setVisible(false);
this.jframe.removeAll();
this.jframe.getContentPane().add(container);
this.mainMenuPanel = null; //mark for garbage collection
this.jframe.setSize(640, 480);
this.jframe.setVisible(true);
this.jframe.validate();
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
