participate


Swing - JTree with XML Content
<<   Back to Forum  |   Give us Feedback
2 Duke Stars available
This topic has 22 replies on 2 pages.    « Previous | 1 | 2 |
debopamghoshal
Posts:178
Registered: 3/30/01
Re: JTree with XML Content   
Dec 21, 2004 4:29 AM (reply 15 of 22)  (In reply to #14 )

 
I am just overriding the following methods in the XMLTreeNode class:-
public boolean equals(Object obj)
public void setParent(javax.swing.tree.MutableTreeNode newParent)
public javax.swing.tree.TreeNode getParent()
public void setUserObject(Object userObject)
public Object getUserObject()
public String toString()

In the equals() method i am comparing the content of the user object which is actually org.jdom.Element.
In the XMLTreeNode class i have private XMLTreeNode parent;, which i am using to set/getparent() methods.
In the set/getUserObject() methods i am setting the nodeElement (private org.jdom.Element nodeElement;)object in the XMLTreeNode class.
In the toString() methog i am returning nodeElement.getTextTrim();
 
dkrukovsky
Posts:417
Registered: 08.10.02
Re: JTree with XML Content   
Dec 21, 2004 4:38 AM (reply 16 of 22)  (In reply to #15 )

 
You might also want to look at dotuseful project and find a similar but easier way to work with trees.

Denis Krukovsky
http://dotuseful.sourceforge.net/
 
weebib
Posts:1,216
Registered: 5/15/03
Re: JTree with XML Content   
Dec 21, 2004 4:46 AM (reply 17 of 22)  (In reply to #16 )

 
Hehe Denis,

The thought just occured to me that the reloading process I was describing earlier could be a good built-in feature of your AutomatedTreeModel.
 
dkrukovsky
Posts:417
Registered: 08.10.02
Re: JTree with XML Content   
Dec 21, 2004 7:30 AM (reply 18 of 22)  (In reply to #17 )

 
Might be a good idea. Thanks weebib. If there are other people interested - please leave your note.

Denis Krukovsky
http://dotuseful.sourceforge.net/
 
debopamghoshal
Posts:178
Registered: 3/30/01
Re: JTree with XML Content   
Dec 21, 2004 9:48 PM (reply 19 of 22)  (In reply to #18 )

 
Denis,
I agree with weebib. It would be of much help if you add the reload feature.

~Debopam
 
hballenchen
Posts:80
Registered: 4/28/04
Re: JTree with XML Content   
Dec 22, 2004 1:42 AM (reply 20 of 22)  (In reply to #15 )

 
I have tried you codes.
As you said, only root node is displayed after xml document loaded.
Do you work out the problem? And what jdom version are you using?
I am very insterested in XML tree.
 
hballenchen
Posts:80
Registered: 4/28/04
Re: JTree with XML Content   
Dec 22, 2004 1:56 AM (reply 21 of 22)  (In reply to original post )

 
Sorry, I do not use asksAllowsChildren argument.
I will learn from your codes. Thank you debopamghoshal.
Here is my test codes.

import javax.swing.*;
 
public class XmlTreeDemo extends JPanel {
    public XmlTreeDemo() {
        XMLTreeModel model = new XMLTreeModel("tree.xml", true);
        JTree tree = new JTree(model);
        add(tree);
    }
 
    private static void createAndShowGUI() {
        JFrame frame = new JFrame("XmlTreeDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        XmlTreeDemo newContentPane = new XmlTreeDemo();
        newContentPane.setOpaque(true);
        frame.setContentPane(newContentPane);
 
        frame.pack();
        frame.setVisible(true);
    }
 
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
 
ohnirboss
Posts:2
Registered: 12/11/06
Re: JTree with XML Content   
May 30, 2007 6:59 AM (reply 22 of 22)  (In reply to #9 )

 
debopamghoshal , I tried to use that code on a school project i'm developing, but some functions weren't known...

also, the XML tree presented didn't have the name of the structure nodes, only the data in the XML file.

Can u help me on this ?

Message was edited by:
ohnirboss
 
This topic has 22 replies on 2 pages.    « Previous | 1 | 2 |
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 54
  • Guests : 123

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums