简体   繁体   中英

Java - Designing a set of Swing components and adding the set dynamically

I am trying to display attributes of an object (let's call it STUFF) in a set of fields. What I would like to do is, for each instance of STUFF, add a JPanel and multiple Jlabels and JTextFields showing the values of the STUFF attributes to a Jframe .

My question would be : Is there any way to design a whole JPanel containing everything I want, use that as a model of some sort, and then, dynamically create an instance of it for each STUFF instance ?

(I am using Netbeans)

You create a Class (CustomPanel) that extends JPanel and there you implement all your fields.

Each time you need to create an additional CustomPanel, you just write

CustomPanel cPanel = new CustomPanel();

and you treat it like a normal JPanel.. Create setter and getter methods to set and get values of the form.

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