Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compilation error when constructing a JTree

Status
Not open for further replies.

koolraul

Programmer
Aug 20, 2003
10
US
I'm experiencing compilation error when I was trying to test my
tree model. In my FileListTreeModel class, which is implementing the
TreeModel interface, I defined the getRoot() as shown below so I can
see its behavior. My tree is being constructed in my JtreeDemo class.
Can anybody show me how I can correct this? Thanks.

/* JtreeDemo class */
iIpAddress = getIpAddress();
FileListTreeModel files = new FileListTreeModel(iIpAddress);
System.out.println("Jtree - root: " + files.getRoot());
DefaultTreeModel model = new DefaultTreeModel(files.getRoot());
JTree tree = new JTree(model);
JPanel panel = new JPanel(new GridLayout(0,1));
panel.add(new JScrollPane(tree));


/* FileListTreeModel class implementing TreeModel */
public Object getRoot() {
System.out.println("getRoot() called!");
Object root = null;
return root;
}


/* Compilation error */
C:\javaprog\cis178\cis178Assignment\Assign5JTree>javac socket\server\*java
socket\server\JtreeDemo.java:48: cannot resolve symbol
symbol : constructor DefaultTreeModel (java.lang.Object)
location: class javax.swing.tree.DefaultTreeModel
DefaultTreeModel model = new DefaultTreeModel(files.getRoot());
^
1 error
 
The DefaultTreeModel constructor requires a "TreeNode" in his constructor instead of an "Object"
Code:
DefaultTreeModel tm = new DefaultTreeModel(new DefaultMutableTreeNode("Root Node"));
====
Why are you creating 2 TreeModels ?
Code:
FileListTreeModel files = new FileListTreeModel(iIpAddress);
DefaultTreeModel model = new DefaultTreeModel(files.getRoot());
 
Hologram,

I commented the other TreeModel and changed my parameter for the JTree constructor and it worked! Thanks for the pointer.

koolraul

/* JtreeDemo class */
iIpAddress = getIpAddress();
FileListTreeModel files = new FileListTreeModel(iIpAddress);
System.out.println("Jtree - root: " + files.getRoot());
//DefaultTreeModel model = new DefaultTreeModel(files.getRoot());
//JTree tree = new JTree(model);
JTree tree = new JTree(files);
JPanel panel = new JPanel(new GridLayout(0,1));
panel.add(new JScrollPane(tree));


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top