Reputation: 43
Is it possible to make a Jpanel, put variables inside of it, and then add the same panel to the content pane multiples times( the number of times based on the number of a certain variable outside of the GUI). AND THEN edit the content inside of each instance individually?
Here is why I need to do the things mentioned above: I'm writing a program that several different clinics can use with minimum setup on the user side. They specify how many bedrooms they have and the my program creates a visual representation of each bedroom automatically. For example: a clinic has 13 rooms so my program adds 13 bedroom Jpanels to the content pane and displays them in numerical order using a fullscreen view.
Upvotes: 0
Views: 328
Reputation: 41208
No, you can't do this. Each JComponent
(which includes JPanel
can have one and only one parent).
You could "fake" it by using a JTable
and having your panel as the cell renderer for the table, that only works if you have no interactive controls inside the panel though.
What you need to do is either create a factory that generates these JPanel
s for you as you need them and just create the number you need or create a new subclass of JPanel
that has everything set up as you like and add new instances of that.
Upvotes: 1
Reputation: 15
I'm still new to Swing and Java, but I suppose you could make a separate class with all of your variables that extends JPanel, and then have an ArrayList of said class, and then .add however many your client has put in. You may not be able to edit them individually without some method of identifying them though.
Upvotes: 0