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.
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.
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!