Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2005

Tip: Looking for answers? Try searching our database.

JTree and own TreeModel

Thread view: 
Rene Ruppert - 23 May 2005 15:01 GMT
Hi,

I use JTree in combination with my own TreeModel. Whenever a new node is to
be inserted I call all listeners to tell them that the structure of the tree
has changed but nothing happens! The new nodes don't appear. What am I
missing? Removing nodes works perfectly...
I figured out that JTree registers itself as a listener but it doesn't seem
to react on changes. I changed the call from "treeStructureChanged" to
"treNodesInserted" - no success either and a look at the source of JTree
says me that the implementation of this method is empty.

Here's piece of the code that informs the listeners:
public void insertItemAdapter(TreeControl.Item abstractItem)
{
// I wrap my nodes into special adapters.
SwingTreeControlItemAdapter newItem =
  new SwingTreeControlItemAdapter(abstractItem);

 // Helps me to find the adapter.
 itemMap.put(abstractItem, newItem);

 // Create a treepath down from the new item up to the root.
 TreePath pathToRoot = getPathToRoot(newItem);

 // Iteratr all listeners.
 Iterator listenerIterator = listeners.iterator();
 TreeModelListener actListener;

 while(listenerIterator.hasNext())
 {
  actListener = (TreeModelListener)listenerIterator.next();

  actListener.treeStructureChanged(new TreeModelEvent(this,
   pathToRoot));
 }
}

Any ideas?

Thanks.

René
Rene Ruppert - 23 May 2005 15:19 GMT
btw: I forgot to mention that it works, when the parent of the new node is
not expanded yet!
Or the other way round: inserting a new node only works, when its' parent is
collapsed...
Rene Ruppert - 23 May 2005 15:51 GMT
Okay, found it...using

actListener.treeNodesInserted(new TreeModelEvent(this, pathToRoot,
childIndices, children));

to create the event shows the new node...

René


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.