tags:

views:

384

answers:

1

Hej

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?

+2  A: 

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

Savvas Dalkitsis
I believe revalidate() should be used for Swing, although 99% of the time either will work.
camickr
revalidate is used to cause all the parents of the component on which it is called to layout their children. For simple use like this one validate will work just fine.
Savvas Dalkitsis