简体   繁体   中英

How do I add components to a JPanel at runtime

I have a JPanel that I want to add some components. in particular JButton s 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?

在将JButton添加到JPanel之后,在JPanel上调用方法validate()

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