[Solved] Game Launcher

Hello,

I am writing my Game Engine from scratch, I decided to make a launcher to have the user open first and log into, get news/updates and download the game cache/updates.

I have it set up to open on a login page and if you click register it should replace the current panel and load the register one.

I have 2 classes, LoginPanel, and RegisterPanel. they both extend JPanel

in the main class I have a JPanel that is the current displayed panel, at launch the current panel is set to the login panel, if you click on register I want to replace the current panel with the registerPanel, but when I do this not all of the panel displays, either the JComboBox for DoB doesn’t render unless you mouse over it, or the old panel will be there behind it still.

I have removed the loginPane from the contentPane and then added the register pane and re validated it, nothing
I have used repaint() and kinda but the JComboBoxes don’t display or the Label doesn’t show.

Bad for explaining things I am sorry, here are some pictures.

JComboBox not fully showing up and the login still in the background.

JComboBox only showing up if you hover over it, but the rest kinda loads

Last this is the content that should be displayed in the Register Panel when updated on the screen

As you can see in the pics, not all of the content is updated properly.

Does anyone know of a way to make this work properly, I can show current code if needed.

Use a CardLayout.

It sounds like you’re manually removing and adding components from your JFrame after it’s already visible, which won’t work. At the very least, you need to revalidate your JFrame after adding a new component to it. Look for useful functions in the API.

But really you should just use CardLayout instead of adding stuff after the JFrame is already visible.

If you’re still stuck, please post a small example program that demonstrates the problem (it should just be a simple JFrame with one or two components, not your whole game), and we’ll go from there. Good luck.

Also be careful to only modify the UI from the AWT event thread. Take a look at SwingUtils.invokeLater()

Thanks for the tip I thought of using the CardLayout but just went another way, idk why lol.

I was declaring them both in the init(), I created 2 JPanels and then made them = the 2 panels (login and register)

and tried to use this


	public void sendRegPanel() {
		contentPane.remove(loginPane); // remove the pane
		contentPane.add(regPane); // set the new pane
		contentPane.revalidate(); // cause yea...
		repaint(); // and just to try see if it works
	}

roughly and I got nothing, I will work out the CardLayout and update this thread

UPDATE:

Solved this issue with the CardLayout, Thanks @KevinWorkman