Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing - CardLayout, how to 'update' cards while running?

I am pretty new at . Java Swing, and am using the CardLayout for my application. In this app a user can create activities and, in an other JPanel, view the existing ones.

I am having trouble updating the card (where the label is in). If I add the activity, when you restart the app it works fine. I am looking for a way that doesn't require restarting.

So in short, I would like to know how I should best reconstruct/update a panel whilst running so that the new label data is shown.

Thanks in advance!

like image 349
belens Avatar asked Jul 23 '26 01:07

belens


1 Answers

When you add a component to a visible GUI you need to tell the GUI that a component has been added so the layout manager can be invoked:

panel.add( component );
panel.revalidate();
like image 115
camickr Avatar answered Jul 26 '26 05:07

camickr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!