Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-22-2008, 07:55 AM
Member
 
Join Date: Jun 2008
Posts: 7
lmsook10 is on a distinguished road
Why my JTree always collasped after refreshing?
Hello,
I have been spending whole day trying to figure out why my JTree always collasped after refreshing, but I haven't got any fruit.


I have a Tree and it is collasped in the beginning, and I can expand and do some work(adding nodes or deleting nodes - no problem)
But there is a button which validates the tree, and if a node has problem, its background changes which part is working Okay.
but the tree always goes back to collasped(original state)

I tried every methods that I searched, but nothing is working.

Below is the codes..

Code:
private void validateManifest() { CP_EditorHandler.checkManifestErrors(_contentPackage, false); ManifestTree manifestTree = _manifestPanel.getManifestTree(); // get the selected node before updating ManifestTreeNode selectedNode = (ManifestTreeNode) manifestTree.getSelectedNode(); // get the selected path before updating TreePath selectedPath = (TreePath) manifestTree.getSelectionPath(); // below code is the part that recreates nodes of the tree and updates nodes' background manifestTree.getModel().setContentPackage(_contentPackage); // I set below code to expand to selected path manifestTree.setExpandsSelectedPaths(true); // I even added this code to make it sure manifestTree.setExpandedState(selectedPath, true); }
I even added addTreeWillExpandListener in the tree constructor, but it doesn't work either.

Code:
addTreeWillExpandListener (new TreeWillExpandListener() { public void treeWillExpand(TreeExpansionEvent e) { } public void treeWillCollapse(TreeExpansionEvent e) throws ExpandVetoException { throw new ExpandVetoException(e, "you can't collapse this JTree"); } });
What did I do wrong or what should I do to make it work?

I really appreciate your help.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-22-2008, 08:08 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,142
hardwired is on a distinguished road
Code:
import java.awt.*; import java.util.Enumeration; import javax.swing.*; import javax.swing.tree.*; public class TreeExpansionTest { private JScrollPane getContent() { JTree tree = new JTree(); expand(tree, tree.getPathForRow(0)); return new JScrollPane(tree); } private void expand(JTree tree, TreePath path) { TreeNode node = (TreeNode)path.getLastPathComponent(); if (node.getChildCount() > 0) { Enumeration e = node.children(); while(e.hasMoreElements()) { TreeNode n = (TreeNode)e.nextElement(); expand(tree, path.pathByAddingChild(n)); } } tree.expandPath(path); } public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new TreeExpansionTest().getContent()); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-24-2008, 06:55 AM
Member
 
Join Date: Jun 2008
Posts: 7
lmsook10 is on a distinguished road
Now I got it work thanks to your codes sample.
Thanks a lot!!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Node selection in jtree Preethi AWT / Swing 4 06-20-2008 12:25 AM
Bug in refreshing jsp anki1234 JavaServer Pages (JSP) and JSTL 2 12-31-2007 08:09 AM
JTree trouble Alantie Vala AWT / Swing 3 08-01-2007 12:12 AM
how to stop refreshing page cecily New To Java 1 07-24-2007 02:25 AM
how to display data in Jtree paty New To Java 1 07-24-2007 01:28 AM


All times are GMT +3. The time now is 04:57 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org