简体   繁体   中英

Switch between different JPanels in one JFrame without CardLayout-buttons

I'm new at Java GUI and I'm trying to make a program that shows a login screen and once logged in, a menu. What I am looking for is a way to navigate through different JPanels in just one JFrame. To navigate the user should use buttons located inside these panels.

I use Netbeans to do this. The furthest I got is to open one JPanel in a JFrame, I've been trying to close one and open another but it won't work because the current panel stays open.

The reason I do not want to use the CardLayout is because I do not wish to have to tabs visible. I don't think you can hide them...

I hope you guy's can help me out,

thanks in advance!!

CardLayout does exactly what you want and absolutely does not require you to use tabs. In fact, the java tutorial on card layout provides a demo that uses a combobox to change between different cards.

Sound like you want to implement a wizard or similar. Take a look at the linked article.

Simply remove the panel from the contentPane and add the new you want to show. This have to be done by code when the button is pressed and all it's ok to change to the next panel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM