File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Swing App Design Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing App Design Question" Watch "Swing App Design Question" New topic

Swing App Design Question

Thomas Hubschman
Ranch Hand

Joined: Sep 25, 2002
Posts: 88
If I want to dyamically build a GUI from an XML file where the number of containers will not be known untill runtime, what is the best method for tracking them? I currently am adding the created containers to a hash map. With a key deliminated in the XML file.
Is this a good solution? Are there better ways?
Many thanks.

SCJP '02, SCWCD '02, SCJD '08, SCSNB '09, SCEA '10
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
I guess you can store your containers in any collections you want: arrays, hashes, Vectors etc. It all comes down to which one is the fastest. Don't you think so?

All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
As an exercise, I'm building something myself to specify a Swing GUI in XML. If a name='aname' attribute is found on any component I put it into a Map. I can create the UI and then get or set values for any of the components. I can also create a listener or model component and reference it by Map key in multiple components.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Have you seen:
Even if you want to design your own and not use those, they should be able to give you some hints as to the best methods to use.

GenRocket - Experts at Building Test Data
Harry Pfohl

Joined: Apr 21, 2001
Posts: 17
see how it is done in JEasy. The hole GUI is stored in XML. To build panels and other components dynamically, JEasy offers a XML-Syntax to create new compnentns at runtime.
To test it, run the Example from and chose the tabbedpane dynamic panel. Change the xml string at the left and build a form.
I agree. Here's the link:
subject: Swing App Design Question
jQuery in Action, 3rd edition