19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

javax.swing.JTree<br />

#cellEdi<strong>to</strong>r: TreeCellEdi<strong>to</strong>r<br />

#cellRenderer: TreeCellRenderer<br />

#editable: boolean<br />

#model: TreeModel<br />

#rootVisible: boolean<br />

#rowHeight: int<br />

#scrollsOnExpand: boo lean<br />

#selectionModel: TreeSelectionModel<br />

#showsRootHandles: boolean<br />

#<strong>to</strong>ggleClick Count: int<br />

-anchorSelectionPath: TreePath<br />

-expandsSelectedPaths: boolean<br />

-leadSelectionPaths: TreePath<br />

+JTree()<br />

+JTree(value: java.util.Hashtable)<br />

+JTree(value: Object[])<br />

+JTree(newModel: TreeModel)<br />

+JTree(root: TreeNode)<br />

+JTree(root: TreeNode, asksAllowsChildren:<br />

boolean)<br />

+JTree(value: Vec<strong>to</strong>r)<br />

+addSelectionPath(path: TreePath): void<br />

+addSelect ionPaths(paths: TreePath[]): void<br />

+addSelectionRow(row: int): void<br />

+addSelectionRows(rows: int[]): void<br />

+clearSelection(): v oid<br />

+collapsePath(path : TreePat h): vo id<br />

+getSel ectionPath(): TreePath<br />

+getSelectionPaths(): TreePath[]<br />

+getLastSelectedPathComponent()<br />

+getRowCount(): int<br />

+removeSelectionPath(path: TreePath): void<br />

+removeSelectionPaths(paths: TreePath[]): void<br />

<strong>Java</strong>Be ans prope rties with get and se t<br />

methods omitted in the UM L diagram<br />

Specifies a cell edi<strong>to</strong>r used <strong>to</strong> edit entries in the tree.<br />

Specifies a cell renderer.<br />

Specifies whether the cell s are editable (defaul t: fals e).<br />

Maintains the tree model.<br />

Specifies whether the root is displayed (depending on the construc<strong>to</strong>r).<br />

Specifies the height of the row for the node displayed in the tree<br />

(default: 16 pixels).<br />

If true, when a node is expanded, as many of the descendants as<br />

possible are scrolled <strong>to</strong> be visible (default: 16 pixels).<br />

Models the set of selected nodes in this tree.<br />

Specifies whether the root handles are displayed (default: true).<br />

Number of mouse clicks before a node is expanded (default: 2).<br />

The path identified as the anchor.<br />

True if paths in the selection should be expanded (default: true).<br />

The path identified as the lead.<br />

Creates a JTree with a sample tree model, as shown in Figure 36.18.<br />

Creates a JTree with an invisible root and the keys in the Hashtable<br />

key/value pairs as its children.<br />

Creates a JTree with an invisible root and the elements in the array as<br />

its ch ildren.<br />

Creates a JTree with the s pecified tree model.<br />

Creates a JTree with the s pecified tree node as its root.<br />

Creates a JTree with the specified tree node as its root and decides<br />

whether a node is a leaf node in the specified manner.<br />

Creates a JTree with an invisible root and the elements in the vec<strong>to</strong>r as<br />

its ch ildren.<br />

Adds the specified TreePath <strong>to</strong> the current selection.<br />

Adds the specified TreePaths <strong>to</strong> the current selection.<br />

Adds the path at the specified row <strong>to</strong> the current selection.<br />

Adds the path at the specified rows <strong>to</strong> the current selection.<br />

Clears the selection.<br />

Ensures that the node identified by the specified path is collapsed and<br />

viewab le.<br />

Returns the path from the root <strong>to</strong> the first selected node.<br />

Returns the paths from the root <strong>to</strong> all the selected nodes.<br />

Returns the last node in the first selected TreePath.<br />

Returns the number of rows currently being displayed.<br />

Removes the node in the specified path.<br />

Removes the node in the specified paths.<br />

Figure 40.20<br />

The JTree class is for creating, cus<strong>to</strong>mizing, and manipulating trees.<br />

The JTree class contains seven construc<strong>to</strong>rs for creating trees.<br />

You can create a tree using its no-arg construc<strong>to</strong>r, a tree model,<br />

a tree node, a Hashtable, an array, or a vec<strong>to</strong>r. Using the no-arg<br />

construc<strong>to</strong>r, a sample tree is created as shown in Figure 40.18.<br />

Using a Hashtable, an array, or a vec<strong>to</strong>r, a root is created but<br />

not displayed. All the keys in a Hashtable, all the objects in an<br />

array, and all the elements in a vec<strong>to</strong>r are added in<strong>to</strong> the tree<br />

as children of the root. If you wish the root <strong>to</strong> be displayed,<br />

set the rootVisible property <strong>to</strong> true.<br />

32

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!