I need to show an xml as a tree structure in a java swing application. When I click on any node in the swing tree its attribute should list in a window (like a properties editor) and from that I need to update the attributes. Also I need to hide some nodes in the xml in the tree.
I am planning to use JTree to populate and show the xml as tree. But bit confused about what approach need to take to read/update the xml.
Currently I have the below options:
Using JAXB create the corresponding objects and populate the JTree
Use any parser DOM or SAX and populate the JTree using the DefaultMutableTreeNode
Please advice what approach I need to proceed? or is there any other better way for doing this?
Related
I have created two Java trees.
Now I want to assign second JTree to first JTree for my further process. How can I do it?
Clone a java TreeModel or are there any special method to do that?
I used ,
firstTree.setModel(secondTree.getModel());
But not successful.
Can you not use the constructor to initialize JTree with existing model :
firstTree=new Jtree(secondTree.getModel());
anyone help me i have Jtree and Subnode i want to click sub node and display one window form in java am using netbeans.
You can achieve this by using a tree selection listener. Look at How to Use Trees tutorial. In particular, Responding to Node Selection section describes how to implement a basic selection listener.
I generated a decision tree based on a set of data, then I converted this data to a xml file, after that I put it into a JTree. This part works fine but now I have to take a new instance(which contains the data received from the user), find it's place in the decision tree and change that node's color. And I can't find a way to do that. I am using weka and the J48 classifier to generate the decision tree. The xml is created in the Luc Sorel style: http://www.lucsorel.com/media/downloads/sample_decision_tree.xml
The first thing I tried was to classify the instance using the algorithm but that gets me only the class where it belongs, and I don't know how to locate it in the JTree.
What should I do? Any ideeas?
Like JTable, JTree uses a flyweight renderer to draw nodes. As the default renderer is a JLabel, you can set the foreground color or make the label opaque and set the background color. This related example changes the icon for emphasis. More examples may be found here.
Addendum: I cannot find … the node that I should color.
When getTreeCellRendererComponent() is called, value is a reference to the node to be rendered, and the tree parameter allows access to the TreeModel as a whole via getModel(). This example shows how to search a tree.
I would like to display html as treeview similar to firebug in my swing. Looking for community help to achieve this. Found similar stuff(Not Exactly) here. But i could not move further with the information in the link.
In general, you need a HTML DOM parser (like JSoup) to create a DOM tree from the HTML code you have. Then you should probably build your own TreeModel to respresent the DOM tree in a swing JTree.
This tutorial will tell you exactly how to create a JTree that shows the DOM structure of an HTML document.
You can use this http://java-sl.com/JEditorPaneStructureTool.html to see how it could be implemented.
After reading HTML with HTMLEditorKit use the HTMLDocument's tree.
What i want to do:
I want to make the menu of my application customizable, giving the user the possibility of changing the order of the menus. For this i have build a tree (rich:tree) representing the menus in my application. By drag-n-drop the user can change the order of the menus.
The menus are kept in a xhtml file (a hierarchical structure of rich:menuGroup and rich:menuItems)
What my problem is:
When the user finishes drag-n-drop, on save i should generate xhtml code corresponding to my tree. More concrete: For each parent node in the tree generate a rich:menuGroup and for each leaf node generate a rich:menuItem. By traversing the tree i should build a hierarchical structure with menu groups containing other menu groups and/or menu items.
Is there any tool or easy way for doing this?
It would be a real pain to traverse the tree and manually concatenate hard-coded strings or something like that.
Thanks
You can use ui:repeat tag, and create menuGroups from an array in the backing bean that you created according to the tree structure. In the array, properties of each menuGroup should be provided.