• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to design a GUI which has n number of component are changing depending on the act  RSS feed

 
kakolia
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have a problem in designing a GUI. The Gui contain number of components which being changing on the frame depending on the action.
For example:
Initial frame contain only the combobox which has few data( let we take tennis, cricket, football..)
If the user select one of this then the frame should add few more component like
cricket should add 24 combobox for selection of the team and the member and the fields to show the information of the individual details.
tennis: should remove the cricket related component and replaced by tennis related component. ....
One more thing is
If we select one of the content of the combo box then it should display the one more combo box.
If we select one from this combo box then it should display one more this should be continue till the user select the end in the combo box.

Please help in this part to complete the designing of the Gui. I want whether we can do add number of components dynamically in a single frame? If possible how?

Thanks in advance
Regards,
kakolia
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
welcome,
one way to do this is to use a CardLayout and select the right panel depending on the combobox selection.
(The CardLayout is like a storage of JPanels where only one at a time is visible. See the swing tutorial for more details:
http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html)
another way to do it, is to add the components dynamically and call repaint() or invalidate() on the container. be sure to add the components and call repaint() inside SwingUtilities.invokeLater(Runnable).
for example:

I hope this can help you a bit.
cheers
 
kakolia
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Thank you for the information what you have provided.
In this case, we cannot expand the frame and more over we donot know how many component will have to show. As i told, till the user select other than end in the combo box we have to display that number of components. It may goes to 1000 components ( worst case may be more than this number ). Kindly reply for this.
Regards,
kakolia.
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, then you have to view your components dynamically. To do this, you should declare a JPanel as the contentholder. If the user presses a button, you remove all components from this panel and then you add all your new components to it. Well this is not so easy, because you have to know which LayoutManager to take. Best for this feature is GridBagLayout. There you can compute the grid position.
After all, you call validateTree for the JPanel.
Hope this is clear

Rene
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"kakolia" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!
 
kakolia
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Thats ok, but How to handle the actions? As I said have number of component. Suppose we use the same type of combo box n number of times. Then we get problem. We have one solution is to addCommandAction for each JComboBox, but in this case we donot know the number of Components.
Regards,
Kakolia
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!