Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add components to a JPanel at runtime

Tags:

java

swing

I have a JPanel that I want to add some components. in particular JButtons to at runtime based on the content of a user supplied file.

I can add compontents to panel if I call it from the constructor of the JFrame derived form class, even after everything else have been constructed, but If I read the file first and then add components to the panel the call succeds but the added components are never shown.

Does anybody know how I force Java to do as I want?

like image 875
tomjen Avatar asked Oct 15 '22 14:10

tomjen


1 Answers

Call the method validate() on the JPanel after you have added the JButtons to it.

like image 198
Savvas Dalkitsis Avatar answered Oct 18 '22 23:10

Savvas Dalkitsis