• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Need to dynamically add checkBoxes in a GUI

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic