|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JTree
public class JTree
Nested Class Summary | |
---|---|
protected class |
JTree.AccessibleJTree
This class implements accessibility support for the JTree class. |
static class |
JTree.DynamicUtilTreeNode
|
protected static class |
JTree.EmptySelectionModel
A TreeModel that does not allow anything to be selected. |
protected class |
JTree.TreeModelHandler
Listens to the model of the JTree and updates the property expandedState if nodes are removed or changed. |
protected class |
JTree.TreeSelectionRedirector
This redirects TreeSelectionEvents and rewrites the source of it to be this JTree. |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
JTree()
Creates a new JTree object. |
|
JTree(Hashtable<?,?> value)
Creates a new JTree object. |
|
JTree(Object[] value)
Creates a new JTree object. |
|
JTree(TreeModel model)
Creates a new JTree object. |
|
JTree(TreeNode root)
Creates a new JTree object. |
|
JTree(TreeNode root,
boolean asksAllowChildren)
Creates a new JTree object. |
|
JTree(Vector<?> value)
Creates a new JTree object. |
Method Summary | |
---|---|
void |
addSelectionInterval(int index0,
int index1)
Select all rows between the two given indexes, inclusive. |
void |
addSelectionPath(TreePath path)
|
void |
addSelectionPaths(TreePath[] paths)
|
void |
addSelectionRow(int row)
|
void |
addSelectionRows(int[] rows)
|
void |
addTreeExpansionListener(TreeExpansionListener listener)
Adds a TreeExpansionListener object to the tree. |
void |
addTreeSelectionListener(TreeSelectionListener listener)
Adds a TreeSelctionListener object to the tree. |
void |
addTreeWillExpandListener(TreeWillExpandListener listener)
Adds a TreeWillExpandListener object to the tree. |
void |
cancelEditing()
|
void |
clearSelection()
|
protected void |
clearToggledPaths()
|
void |
collapsePath(TreePath path)
|
void |
collapseRow(int row)
|
String |
convertValueToText(Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus)
Converts the specified value to a String. |
protected static TreeModel |
createTreeModel(Object value)
Creates a new TreeModel object. |
protected TreeModelListener |
createTreeModelListener()
Creates and returns an instance of JTree.TreeModelHandler . |
void |
expandPath(TreePath path)
|
void |
expandRow(int row)
|
void |
fireTreeCollapsed(TreePath path)
Notifies all listeners that the tree was collapsed. |
void |
fireTreeExpanded(TreePath path)
Notifies all listeners that the tree was expanded. |
void |
fireTreeWillCollapse(TreePath path)
Notifies all listeners that the tree will collapse. |
void |
fireTreeWillExpand(TreePath path)
Notifies all listeners that the tree will expand. |
protected void |
fireValueChanged(TreeSelectionEvent event)
Notifies all listeners when the selection of the tree changed. |
AccessibleContext |
getAccessibleContext()
Gets the AccessibleContext associated with this JTree . |
TreePath |
getAnchorSelectionPath()
|
TreeCellEditor |
getCellEditor()
|
TreeCellRenderer |
getCellRenderer()
|
TreePath |
getClosestPathForLocation(int x,
int y)
|
int |
getClosestRowForLocation(int x,
int y)
|
protected static TreeModel |
getDefaultTreeModel()
Returns a sample TreeModel that can be used in a JTree. |
protected Enumeration<TreePath> |
getDescendantToggledPaths(TreePath parent)
|
boolean |
getDragEnabled()
Return the value of the dragEnabled property. |
TreePath |
getEditingPath()
|
Enumeration<TreePath> |
getExpandedDescendants(TreePath path)
Returns all TreePath objects which are a descendants of the given path and are exapanded at the moment of the execution of this method. |
boolean |
getExpandsSelectedPaths()
|
boolean |
getInvokesStopCellEditing()
|
Object |
getLastSelectedPathComponent()
|
TreePath |
getLeadSelectionPath()
|
int |
getLeadSelectionRow()
|
int |
getMaxSelectionRow()
|
int |
getMinSelectionRow()
|
TreeModel |
getModel()
Returns the model of this JTree object. |
TreePath |
getNextMatch(String prefix,
int startingRow,
Position.Bias bias)
Returns the next table element (beginning from the row startingRow that starts with prefix . |
protected TreePath[] |
getPathBetweenRows(int index0,
int index1)
Get the pathes that are displayes between the two given rows. |
Rectangle |
getPathBounds(TreePath path)
|
TreePath |
getPathForLocation(int x,
int y)
|
TreePath |
getPathForRow(int row)
|
Dimension |
getPreferredScrollableViewportSize()
Returns the preferred viewport size. |
Rectangle |
getRowBounds(int row)
|
int |
getRowCount()
|
int |
getRowForLocation(int x,
int y)
|
int |
getRowForPath(TreePath path)
|
int |
getRowHeight()
|
int |
getScrollableBlockIncrement(Rectangle visibleRect,
int orientation,
int direction)
Return the preferred scrolling amount (in pixels) for the given scrolling direction and orientation when scrolling in large amounts (pages). |
boolean |
getScrollableTracksViewportHeight()
Return true if the height of the scrollable is always equal to the view, where it is displayed, height.In such case, the vertical scrolling should not be performed. |
boolean |
getScrollableTracksViewportWidth()
Return true if the width of the scrollable is always equal to the view, where it is displayed, width (for instance, the text area with the word wrap). |
int |
getScrollableUnitIncrement(Rectangle visibleRect,
int orientation,
int direction)
Return the preferred scrolling amount (in pixels) for the given scrolling direction and orientation. |
boolean |
getScrollsOnExpand()
|
int |
getSelectionCount()
|
TreeSelectionModel |
getSelectionModel()
|
TreePath |
getSelectionPath()
|
TreePath[] |
getSelectionPaths()
|
int[] |
getSelectionRows()
|
boolean |
getShowsRootHandles()
|
int |
getToggleClickCount()
|
TreeExpansionListener[] |
getTreeExpansionListeners()
Returns all added TreeExpansionListener objects. |
TreeSelectionListener[] |
getTreeSelectionListeners()
Returns all added TreeSelectionListener objects. |
TreeWillExpandListener[] |
getTreeWillExpandListeners()
Returns all added TreeWillExpandListener objects. |
TreeUI |
getUI()
Return the UI associated with this JTree object. |
String |
getUIClassID()
This method returns the String ID of the UI class of Separator. |
int |
getVisibleRowCount()
|
boolean |
hasBeenExpanded(TreePath path)
|
boolean |
isCollapsed(int row)
|
boolean |
isCollapsed(TreePath path)
|
boolean |
isEditable()
Checks if this JTree object is editable. |
boolean |
isEditing()
|
boolean |
isExpanded(int row)
|
boolean |
isExpanded(TreePath path)
|
boolean |
isFixedRowHeight()
|
boolean |
isLargeModel()
|
boolean |
isPathEditable(TreePath path)
|
boolean |
isPathSelected(TreePath path)
|
boolean |
isRootVisible()
Checks if the root element is visible. |
boolean |
isRowSelected(int row)
Returns true when the specified row is selected,
false otherwise. |
boolean |
isSelectionEmpty()
|
boolean |
isVisible(TreePath path)
|
void |
makeVisible(TreePath path)
|
protected String |
paramString()
A String representation of this JTree. |
protected boolean |
removeDescendantSelectedPaths(TreePath path,
boolean includeSelected)
Removes any paths in the current set of selected paths that are descendants of path . |
protected void |
removeDescendantToggledPaths(Enumeration<TreePath> toRemove)
Removes any descendants of the TreePaths in toRemove that have been expanded. |
void |
removeSelectionInterval(int index0,
int index1)
|
void |
removeSelectionPath(TreePath path)
|
void |
removeSelectionPaths(TreePath[] paths)
|
void |
removeSelectionRow(int row)
|
void |
removeSelectionRows(int[] rows)
|
void |
removeTreeExpansionListener(TreeExpansionListener listener)
Removes a TreeExpansionListener object from the tree. |
void |
removeTreeSelectionListener(TreeSelectionListener listener)
Removes a TreeSelectionListener object from the tree. |
void |
removeTreeWillExpandListener(TreeWillExpandListener listener)
Removes a TreeWillExpandListener object from the tree. |
void |
scrollPathToVisible(TreePath path)
|
void |
scrollRowToVisible(int row)
|
void |
setAnchorSelectionPath(TreePath path)
|
void |
setCellEditor(TreeCellEditor editor)
|
void |
setCellRenderer(TreeCellRenderer newRenderer)
|
void |
setDragEnabled(boolean enabled)
Set the dragEnabled property. |
void |
setEditable(boolean flag)
Sets the editable property. |
protected void |
setExpandedState(TreePath path,
boolean state)
|
void |
setExpandsSelectedPaths(boolean flag)
|
void |
setInvokesStopCellEditing(boolean invoke)
|
void |
setLargeModel(boolean large)
|
void |
setLeadSelectionPath(TreePath path)
|
void |
setModel(TreeModel model)
Sets the model to use in JTree . |
void |
setRootVisible(boolean flag)
|
void |
setRowHeight(int height)
|
void |
setScrollsOnExpand(boolean scroll)
|
void |
setSelectionInterval(int index0,
int index1)
|
void |
setSelectionModel(TreeSelectionModel model)
|
void |
setSelectionPath(TreePath path)
|
void |
setSelectionPaths(TreePath[] paths)
|
void |
setSelectionRow(int row)
|
void |
setSelectionRows(int[] rows)
|
void |
setShowsRootHandles(boolean flag)
|
void |
setToggleClickCount(int count)
|
void |
setUI(TreeUI ui)
Sets the UI associated with this JTree object. |
void |
setVisibleRowCount(int rows)
|
void |
startEditingAtPath(TreePath path)
|
boolean |
stopEditing()
|
void |
treeDidChange()
Sent when the tree has changed enough that we need to resize the bounds, but not enough that we need to remove the expanded node set (e.g nodes were expanded or collapsed, or nodes were inserted into the tree). |
void |
updateUI()
This method resets the UI used to the Look and Feel defaults.. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String CELL_EDITOR_PROPERTY
public static final String CELL_RENDERER_PROPERTY
public static final String EDITABLE_PROPERTY
public static final String INVOKES_STOP_CELL_EDITING_PROPERTY
public static final String LARGE_MODEL_PROPERTY
public static final String ROOT_VISIBLE_PROPERTY
public static final String ROW_HEIGHT_PROPERTY
public static final String SCROLLS_ON_EXPAND_PROPERTY
public static final String SELECTION_MODEL_PROPERTY
public static final String SHOWS_ROOT_HANDLES_PROPERTY
public static final String TOGGLE_CLICK_COUNT_PROPERTY
public static final String TREE_MODEL_PROPERTY
public static final String VISIBLE_ROW_COUNT_PROPERTY
public static final String ANCHOR_SELECTION_PATH_PROPERTY
public static final String LEAD_SELECTION_PATH_PROPERTY
public static final String EXPANDS_SELECTED_PATHS_PROPERTY
protected transient TreeCellEditor cellEditor
protected transient TreeCellRenderer cellRenderer
protected boolean editable
protected boolean invokesStopCellEditing
protected boolean largeModel
protected boolean rootVisible
protected int rowHeight
protected boolean scrollsOnExpand
protected transient TreeSelectionModel selectionModel
protected boolean showsRootHandles
protected int toggleClickCount
protected transient TreeModel treeModel
protected int visibleRowCount
protected transient TreeModelListener treeModelListener
protected JTree.TreeSelectionRedirector selectionRedirector
Constructor Detail |
---|
public JTree()
JTree
object.
public JTree(Hashtable<?,?> value)
JTree
object.
value
- the initial nodes in the treepublic JTree(Object[] value)
JTree
object.
value
- the initial nodes in the treepublic JTree(TreeModel model)
JTree
object.
model
- the model to usepublic JTree(TreeNode root)
JTree
object.
root
- the root nodepublic JTree(TreeNode root, boolean asksAllowChildren)
JTree
object.
root
- the root nodeasksAllowChildren
- if false, all nodes without children are leaf
nodes. If true, only nodes that do not allow children are leaf
nodes.public JTree(Vector<?> value)
JTree
object.
value
- the initial nodes in the treeMethod Detail |
---|
public int getRowForPath(TreePath path)
public TreePath getPathForRow(int row)
protected TreePath[] getPathBetweenRows(int index0, int index1)
index0
- the starting row, inclusiveindex1
- the ending row, inclusive
protected static TreeModel createTreeModel(Object value)
TreeModel
object.
value
- the values stored in the modelpublic TreeUI getUI()
JTree
object.
TreeUI
objectpublic void setUI(TreeUI ui)
JTree
object.
ui
- the TreeUI
to associatepublic void updateUI()
updateUI
in class JComponent
public String getUIClassID()
getUIClassID
in class JComponent
JComponent.setUI(javax.swing.plaf.ComponentUI)
,
JComponent.updateUI()
public AccessibleContext getAccessibleContext()
JTree
.
getAccessibleContext
in interface Accessible
getAccessibleContext
in class JComponent
public Dimension getPreferredScrollableViewportSize()
getPreferredScrollableViewportSize
in interface Scrollable
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
getScrollableUnitIncrement
in interface Scrollable
visibleRect
- the currently visible part of the component.orientation
- the scrolling orientationdirection
- the scrolling direction (negative - up, positive -down).
The values greater than one means that more mouse wheel or similar
events were generated, and hence it is better to scroll the longer
distance.
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
Scrollable
getScrollableBlockIncrement
in interface Scrollable
visibleRect
- the currently visible part of the component.orientation
- the scrolling orientationdirection
- the scrolling direction (negative - up, positive -down).
The values greater than one means that more mouse wheel or similar
events were generated, and hence it is better to scroll the longer
distance.
public boolean getScrollableTracksViewportHeight()
Scrollable
getScrollableTracksViewportHeight
in interface Scrollable
public boolean getScrollableTracksViewportWidth()
Scrollable
getScrollableTracksViewportWidth
in interface Scrollable
public void addTreeExpansionListener(TreeExpansionListener listener)
TreeExpansionListener
object to the tree.
listener
- the listener to addpublic void removeTreeExpansionListener(TreeExpansionListener listener)
TreeExpansionListener
object from the tree.
listener
- the listener to removepublic TreeExpansionListener[] getTreeExpansionListeners()
TreeExpansionListener
objects.
public void fireTreeCollapsed(TreePath path)
path
- the path to the node that was collapsedpublic void fireTreeExpanded(TreePath path)
path
- the path to the node that was expandedpublic void addTreeSelectionListener(TreeSelectionListener listener)
TreeSelctionListener
object to the tree.
listener
- the listener to addpublic void removeTreeSelectionListener(TreeSelectionListener listener)
TreeSelectionListener
object from the tree.
listener
- the listener to removepublic TreeSelectionListener[] getTreeSelectionListeners()
TreeSelectionListener
objects.
protected void fireValueChanged(TreeSelectionEvent event)
event
- the event to sendpublic void addTreeWillExpandListener(TreeWillExpandListener listener)
TreeWillExpandListener
object to the tree.
listener
- the listener to addpublic void removeTreeWillExpandListener(TreeWillExpandListener listener)
TreeWillExpandListener
object from the tree.
listener
- the listener to removepublic TreeWillExpandListener[] getTreeWillExpandListeners()
TreeWillExpandListener
objects.
public void fireTreeWillCollapse(TreePath path) throws ExpandVetoException
path
- the path to the node that will collapse
ExpandVetoException
public void fireTreeWillExpand(TreePath path) throws ExpandVetoException
path
- the path to the node that will expand
ExpandVetoException
public TreeModel getModel()
JTree
object.
TreeModel
public void setModel(TreeModel model)
JTree
.
model
- the TreeModel
to usepublic boolean isEditable()
JTree
object is editable.
true
if this tree object is editable,
false
otherwisepublic void setEditable(boolean flag)
editable
property.
flag
- true
to make this tree object editable,
false
otherwisepublic boolean isRootVisible()
true
if the root element is visible,
false
otherwisepublic void setRootVisible(boolean flag)
public boolean getShowsRootHandles()
public void setShowsRootHandles(boolean flag)
public TreeCellEditor getCellEditor()
public void setCellEditor(TreeCellEditor editor)
public TreeCellRenderer getCellRenderer()
public void setCellRenderer(TreeCellRenderer newRenderer)
public TreeSelectionModel getSelectionModel()
public void setSelectionModel(TreeSelectionModel model)
public int getVisibleRowCount()
public void setVisibleRowCount(int rows)
public boolean isLargeModel()
public void setLargeModel(boolean large)
public int getRowHeight()
public void setRowHeight(int height)
public boolean isFixedRowHeight()
public boolean getInvokesStopCellEditing()
public void setInvokesStopCellEditing(boolean invoke)
public int getToggleClickCount()
public void setToggleClickCount(int count)
public void scrollPathToVisible(TreePath path)
public void scrollRowToVisible(int row)
public boolean getScrollsOnExpand()
public void setScrollsOnExpand(boolean scroll)
public void setSelectionPath(TreePath path)
public void setSelectionPaths(TreePath[] paths)
public void setSelectionRow(int row)
public void setSelectionRows(int[] rows)
public void setSelectionInterval(int index0, int index1)
public void addSelectionPath(TreePath path)
public void addSelectionPaths(TreePath[] paths)
public void addSelectionRow(int row)
public void addSelectionRows(int[] rows)
public void addSelectionInterval(int index0, int index1)
index0
- the starting row, inclusiveindex1
- the ending row, inclusivepublic void removeSelectionPath(TreePath path)
public void removeSelectionPaths(TreePath[] paths)
public void removeSelectionRow(int row)
public void removeSelectionRows(int[] rows)
public void removeSelectionInterval(int index0, int index1)
public void clearSelection()
public TreePath getLeadSelectionPath()
public void setLeadSelectionPath(TreePath path)
public TreePath getAnchorSelectionPath()
public void setAnchorSelectionPath(TreePath path)
public int getLeadSelectionRow()
public int getMaxSelectionRow()
public int getMinSelectionRow()
public int getSelectionCount()
public TreePath getSelectionPath()
public TreePath[] getSelectionPaths()
public int[] getSelectionRows()
public boolean isPathSelected(TreePath path)
public boolean isRowSelected(int row)
true
when the specified row is selected,
false
otherwise. This call is delegated to the
TreeSelectionModel.isRowSelected(int)
method.
row
- the row to check
true
when the specified row is selected,
false
otherwisepublic boolean isSelectionEmpty()
public boolean getDragEnabled()
dragEnabled
property.
public void setDragEnabled(boolean enabled)
dragEnabled
property.
enabled
- new valuepublic int getRowCount()
public void collapsePath(TreePath path)
public void collapseRow(int row)
public void expandPath(TreePath path)
public void expandRow(int row)
public boolean isCollapsed(TreePath path)
public boolean isCollapsed(int row)
public boolean isExpanded(TreePath path)
public boolean isExpanded(int row)
public boolean getExpandsSelectedPaths()
public void setExpandsSelectedPaths(boolean flag)
public Rectangle getPathBounds(TreePath path)
public Rectangle getRowBounds(int row)
public boolean isEditing()
public boolean stopEditing()
public void cancelEditing()
public void startEditingAtPath(TreePath path)
public TreePath getEditingPath()
public TreePath getPathForLocation(int x, int y)
public int getRowForLocation(int x, int y)
public TreePath getClosestPathForLocation(int x, int y)
public int getClosestRowForLocation(int x, int y)
public Object getLastSelectedPathComponent()
protected void setExpandedState(TreePath path, boolean state)
protected void clearToggledPaths()
protected Enumeration<TreePath> getDescendantToggledPaths(TreePath parent)
public boolean hasBeenExpanded(TreePath path)
public boolean isVisible(TreePath path)
public void makeVisible(TreePath path)
public boolean isPathEditable(TreePath path)
protected TreeModelListener createTreeModelListener()
JTree.TreeModelHandler
.
JTree.TreeModelHandler
protected static TreeModel getDefaultTreeModel()
public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
value.toString()
and
ignores all other parameters. Subclass this method to control the
conversion.
value
- the value that is converted to a Stringselected
- indicates if that value is selected or notexpanded
- indicates if that value is expanded or notleaf
- indicates if that value is a leaf node or notrow
- the row of the nodehasFocus
- indicates if that node has focus or notprotected String paramString()
null
.
paramString
in class JComponent
public Enumeration<TreePath> getExpandedDescendants(TreePath path)
path
- The parent of this request
public TreePath getNextMatch(String prefix, int startingRow, Position.Bias bias)
startingRow
that starts with prefix
.
Searching is done in the direction specified by bias
.
prefix
- the prefix to search for in the cell valuesstartingRow
- the index of the row where to start searching frombias
- the search direction, either Position.Bias#Forward
or
Position.Bias#Backward
IllegalArgumentException
- if prefix is null
or
startingRow is not validprotected boolean removeDescendantSelectedPaths(TreePath path, boolean includeSelected)
path
. If includePath
is set
to true
and path
itself is selected, then
it will be removed too.
path
- the path from which selected descendants are to be removedincludeSelected
- if true
then path
itself
will also be remove if it's selected
true
if something has been removed,
false
otherwiseprotected void removeDescendantToggledPaths(Enumeration<TreePath> toRemove)
toRemove
- - Enumeration of TreePaths that need to be removed from
cache of toggled tree paths.public void treeDidChange()
Sent when the tree has changed enough that we need to resize the bounds, but not enough that we need to remove the expanded node set (e.g nodes were expanded or collapsed, or nodes were inserted into the tree). You should never have to invoke this, the UI will invoke this as it needs to.
If the tree uses DefaultTreeModel
, you must call
DefaultTreeModel.reload(TreeNode)
or
DefaultTreeModel.reload()
after adding or removing nodes. Following
the official Java 1.5 API standard, just calling treeDidChange, repaint()
or revalidate() does not update the tree appearance properly.
DefaultTreeModel.reload()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |