JTree in Java Swing

Home  »  Java  »  Advance Java  »  Java Swing II  »  JTree


A control that displays a set of hierarchical data as an outline. A specific node in a tree can be identified either by a TreePath (an object that encapsulates a node and all of its ancestors), or by its display row, where each row in the display area displays one node. An expanded node is a non-leaf node (as identified by TreeModel.isLeaf(node) returning false) that will displays its children when all its ancestors are expanded. A collapsed node is one which hides them. A hidden node is one which is under a collapsed ancestor. All of a viewable nodes parents are expanded, but may or may not be displayed. A displayed node is both viewable and in the display area, where it can be seen.

JTree displays its data vertically. Each row displayed by the tree contains exactly one item of data, which is called a node. Every tree has a root node from which all nodes descend. By default, the tree displays the root node, but you can decree otherwise. A node can either have children or not. We refer to nodes that can have children — whether or not they currently have children — as branch nodes. Nodes that can not have children are leaf nodes.

The following JTree methods use "visible" to mean "displayed":

  1. isRootVisible()
  2. setRootVisible()
  3. scrollPathToVisible()
  4. scrollRowToVisible()
  5. getVisibleRowCount()
  6. setVisibleRowCount()
The next group of JTree methods use "visible" to mean "viewable" (under an expanded parent):

  1. isVisible()
  2. makeVisible()


The below program show how to use JTree in java swing...



C:\>jdk1.4\bin>javac JTreeDemo.java
C:\>jdk1.4\bin>java JTreeDemo



"Output of JTreeDemo.class"


Download Complete Program

  -  



Java Swing-II


JOptionPane Class Input Dialog Boxes JSliders
JProgressBars JTables JTabbedPane
JMenu JPopupMenu JToolBar
JFileChooser JScrollBar JScrollPane
JRootPane JTextPane JTree
JSplitPane JDesktopPane JEditorPane




No comments:

Post a Comment