Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to dynamically add checkBoxes in a GUI

 
Roshan Khandelwal
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone ,
I have encountered a issue or better said technical ignorance roadblock.

I need to be able to add 'x' number of JPanel dynamically in a GUI window.
(Each of these JPanel further have a checkBox,JLabel and three JRadioButtons.)

By Dynamically i mean , the code runs... finds out that we need to add , say 10 JPanels and after the code has run or maybe even within the run , these JPanels are added to the GUI .

Any help or tutorial link would be appreciated.
 
Maneesh Godbole
Saloon Keeper
Posts: 11185
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you got so far and where are you stuck?

Usually this is the way its done (in pseudo code)
1) Define parent panel. Set appropriate layout to the parent
2) Create the child components
3) Add the children to the parent
4) After adding all the children, call parent.revalidate() and parent.repaint()
 
Rohit Kedia
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there ,
I had a Similar requirement here , I was able to add child Panels(which consisted of some Components) to a Parent Panel , but problem was that after adding say 10 Panels(which actually depends on my Panel size , which could fit 10 child Panels say) all the newly added child Panels were getting squeezed within that . I had kept that Parent Panel in a ScrollPane but it didnt work.

I tried to increase Panel size every time I add a child Panel still it didn't work.

Note:
I was using a Button to add child Panels.

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rohit Kedia wrote:
I was able to add child Panels(which consisted of some Components) to a Parent Panel , but problem was that after adding say 10 Panels(which actually depends on my Panel size , which could fit 10 child Panels say) all the newly added child Panels were getting squeezed within that . I had kept that Parent Panel in a ScrollPane but it didnt work.
I tried to increase Panel size every time I add a child Panel still it didn't work.


If you nest components and try out different layout managers, this can be made to work without difficulty. For instance one way (and I'm not saying it's the best way, just that it works), is to place the check box containing JPanels into a GridLayout(0, 1) using JPanel, that is placed BorderLayout.NORTH into a BorderLayout using JPanel, that is placed into a JScrollPane.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> (Each of these JPanel further have a checkBox,JLabel and three JRadioButtons.)

if the panels are identical (some sort of quiz?), do they all need to be visible together?

if not, perhaps adding them as a CardLayout might suit i.e. next, next, next etc
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic