• Post Reply Bookmark Topic Watch Topic
  • New Topic

dynamic GUI  RSS feed

 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
Im creating a GUI containing some labels & texfields , these components can be added dynamically, but I will be able to know how many components are there, so which layout is preferable in this case? I was thinkin of using a loop & laying out the components using GridBagLayout. Is there any better way from design point of view?
Regards,
Vinod
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The layout depends on how you want it to look.
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose say, I want a label with a textfield besides it..this pattern is to be followed vertically till a fixed point is reached then , then the components folowing after that need to placed besides the previous one..i.e, label,textfield, a space ,label,texfield & so on..this will depend on the no. of components I get while building the GUI.
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Actually the specs are like this:A label is followed by a JComboBox, now based on the values selected in the Combobox, either a Textfield or another combobox appears to the right of the previous combobox, this second combox will also spawn textfields / comboxes. So I have to keep adding & removing these components dynamically. I have acheived some success, like trying to call a recursive method to keep adding components, but at when some values of a combobox get selected their respective child components get added again & again. I'm unable to keep track of the previous component so I can do removeAll() in some way. Any ideas? whew:-)
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep track of all your components in an Array. For instance, everytime you create a textField do something like JTextField[n] = new JTextField() where n is your position in the Array.
Then you will always know where every single component is.

------------------
Happy Coding,
Gregg Bolinger
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!