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 Display contents in GUI format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Display contents in GUI format" Watch "Display contents in GUI format" New topic

Display contents in GUI format

Avinash Rakkasagi

Joined: Nov 24, 2011
Posts: 8
Hi, I have a Java code which displays the contents of a XML file in text format when used in NetBeans IDE. Can someone please modify the code so that I can display the result in GUI format with compress and expand features i.e I want the result in tree structure with compress and expand features added to the tree.

Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1599
Avinash Rakkasagi wrote:
Urgent help required!!!

Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Ranganathan Kaliyur Mannar

Joined: Oct 16, 2003
Posts: 1101

You have to use a JTree for this purpose. And you also need to write your TreeModel to hold the data. Expansion and Collapse stuff is automatically provided by the JTree component.
I suggest you go throught the tutorial which is a great place to start.

Roberto Perillo

Joined: Dec 28, 2007
Posts: 2271

Avinash Rakkasagi wrote:Can someone please modify the code so that I can display the result in GUI format with compress and expand features

Well champ, you have to TellTheDetails. For instance, what is the structure of your XML file? Where/how do you want it do be displayed?

Anyway, we'll do even better: you will tell you how you could structure your code so you can achieve your goal!

First, what you can do is define an interface that will abstract the reading of your XML file. You have nodes that represent a data structure that keeps information about particular objects in your XML, right? Let's say that your XML file keeps information about people, so let's say that the node is Person. In the constructor of the implementation of this interface, you can read the XML file, given its path. Then, you can consume the methods offered by this interface in your window. You can instantiate the objects in the main method of your application.

Please take a look at it and let us know if you have doubts!

Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
I agree. Here's the link:
subject: Display contents in GUI format
It's not a secret anymore!