Java Doc for TreeModel.java in  » 6.0-JDK-Core » swing » javax » swing » tree » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » swing » javax.swing.tree 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


javax.swing.tree.TreeModel

All known Subclasses:   javax.swing.tree.DefaultTreeModel,
TreeModel
public interface TreeModel (Code)
The model used by JTree.

JTree and its related classes make extensive use of TreePaths for indentifying nodes in the TreeModel. If a TreeModel returns the same object, as compared by equals, at two different indices under the same parent than the resulting TreePath objects will be considered equal as well. Some implementations may assume that if two TreePaths are equal, they identify the same node. If this condition is not met, painting problems and other oddities may result. In other words, if getChild for a given parent returns the same Object (as determined by equals) problems may result, and it is recommended you avoid doing this.

Similarly JTree and its related classes place TreePaths in Maps. As such if a node is requested twice, the return values must be equal (using the equals method) and have the same hashCode.

For further information on tree models, including an example of a custom implementation, see How to Use Trees in The Java Tutorial.
See Also:   TreePath
version:
   1.32 05/05/07
author:
   Rob Davis
author:
   Ray Ryan





Method Summary
 voidaddTreeModelListener(TreeModelListener l)
     Adds a listener for the TreeModelEvent posted after the tree changes.
public  ObjectgetChild(Object parent, int index)
     Returns the child of parent at index index in the parent's child array.
public  intgetChildCount(Object parent)
     Returns the number of children of parent. Returns 0 if the node is a leaf or if it has no children.
public  intgetIndexOfChild(Object parent, Object child)
     Returns the index of child in parent.
public  ObjectgetRoot()
     Returns the root of the tree.
public  booleanisLeaf(Object node)
     Returns true if node is a leaf.
 voidremoveTreeModelListener(TreeModelListener l)
     Removes a listener previously added with addTreeModelListener.
public  voidvalueForPathChanged(TreePath path, Object newValue)
     Messaged when the user has altered the value for the item identified by path to newValue.



Method Detail
addTreeModelListener
void addTreeModelListener(TreeModelListener l)(Code)
Adds a listener for the TreeModelEvent posted after the tree changes.
Parameters:
  l - the listener to add
See Also:   TreeModel.removeTreeModelListener



getChild
public Object getChild(Object parent, int index)(Code)
Returns the child of parent at index index in the parent's child array. parent must be a node previously obtained from this data source. This should not return null if index is a valid index for parent (that is index >= 0 && index < getChildCount(parent)).
Parameters:
  parent - a node in the tree, obtained from this data source the child of parent at index index



getChildCount
public int getChildCount(Object parent)(Code)
Returns the number of children of parent. Returns 0 if the node is a leaf or if it has no children. parent must be a node previously obtained from this data source.
Parameters:
  parent - a node in the tree, obtained from this data source the number of children of the node parent



getIndexOfChild
public int getIndexOfChild(Object parent, Object child)(Code)
Returns the index of child in parent. If either parent or child is null, returns -1. If either parent or child don't belong to this tree model, returns -1.
Parameters:
  parent - a node in the tree, obtained from this data source
Parameters:
  child - the node we are interested in the index of the child in the parent, or -1 if eitherchild or parent are nullor don't belong to this tree model



getRoot
public Object getRoot()(Code)
Returns the root of the tree. Returns null only if the tree has no nodes. the root of the tree



isLeaf
public boolean isLeaf(Object node)(Code)
Returns true if node is a leaf. It is possible for this method to return false even if node has no children. A directory in a filesystem, for example, may contain no files; the node representing the directory is not a leaf, but it also has no children.
Parameters:
  node - a node in the tree, obtained from this data source true if node is a leaf



removeTreeModelListener
void removeTreeModelListener(TreeModelListener l)(Code)
Removes a listener previously added with addTreeModelListener.
See Also:   TreeModel.addTreeModelListener
Parameters:
  l - the listener to remove



valueForPathChanged
public void valueForPathChanged(TreePath path, Object newValue)(Code)
Messaged when the user has altered the value for the item identified by path to newValue. If newValue signifies a truly new value the model should post a treeNodesChanged event.
Parameters:
  path - path to the node that the user has altered
Parameters:
  newValue - the new value from the TreeCellEditor



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.