public interface TreeSelectionModel 
       树选择的状态由一组TreePaths和可选的一组整数表征。 从TreePath到整数的映射是通过RowMapper的一个实例来完成的。 TreeSelectionModel没有必要使RowMapper正确运行,但没有RowMapper getSelectionRows将返回null。 
 可以将TreeSelectionModel配置为仅允许一个路径( SINGLE_TREE_SELECTION )多个连续路径( CONTIGUOUS_TREE_SELECTION )或多个不连续路径( DISCONTIGUOUS_TREE_SELECTION )。 A RowMapper用于确定TreePath是否是连续的。 在没有RowMapper CONTIGUOUS_TREE_SELECTION和DISCONTIGUOUS_TREE_SELECTION行为相同的情况下,就是它们允许在TreeSelectionModel中包含任意数量的路径。 
 对于选择模型CONTIGUOUS_TREE_SELECTION的路径被变更的任何时间( setSelectionPath , addSelectionPath ...)的TreePath,则再次检查,以他们是连续的。 还可以通过调用resetRowSelection来强制对resetRowSelection 。 一组不连贯的TreePath如何映射到一个连续的集合是由这个接口的实现者执行一个特定的策略。 
实现应该将添加到选择中的重复TreePath组合起来。 例如,以下代码
  TreePath[] paths = new TreePath[] { treePath, treePath };
   treeSelectionModel.setSelectionPaths(paths);  
       应该只能选择一个路径: treePath ,而不是treePath两个treePath 。 
       引导TreePath是添加(或设置)的最后一个路径。 那么引导行就是从RowMapper确定的对应于TreePath的行。
| Modifier and Type | Field and Description | 
|---|---|
| static int | CONTIGUOUS_TREE_SELECTION
              选择只能是连续的。 
             | 
| static int | DISCONTIGUOUS_TREE_SELECTION
              选择可以包含任何数量的不一定连续的项目。 
             | 
| static int | SINGLE_TREE_SELECTION
              选择一次只能包含一个路径。 
             | 
| Modifier and Type | Method and Description | 
|---|---|
| void | addPropertyChangeListener(PropertyChangeListener listener)
              将PropertyChangeListener添加到侦听器列表。 
             | 
| void | addSelectionPath(TreePath path)
              添加当前选择的路径。 
             | 
| void | addSelectionPaths(TreePath[] paths)
              将路径添加到当前选择。 
             | 
| void | addTreeSelectionListener(TreeSelectionListener x)
              将x添加到每次选定的TreePath集合更改时通知的侦听器列表。 
             | 
| void | clearSelection()
              清空当前的选择。 
             | 
| TreePath | getLeadSelectionPath()
              返回添加的最后一个路径。 
             | 
| int | getLeadSelectionRow()
              返回引导选择索引。 
             | 
| int | getMaxSelectionRow()
              返回从当前所选TreePath集合的RowMapper获取的最大值。 
             | 
| int | getMinSelectionRow()
              返回从当前所选TreePath集合的RowMapper获取的最小值。 
             | 
| RowMapper | getRowMapper()
              返回能够将TreePath映射到行的RowMapper实例。 
             | 
| int | getSelectionCount()
              返回所选路径的数量。 
             | 
| int | getSelectionMode()
              返回当前选择模式,一个 
              SINGLE_TREE_SELECTION,CONTIGUOUS_TREE_SELECTION或DISCONTIGUOUS_TREE_SELECTION。 | 
| TreePath | getSelectionPath()
              返回选择中的第一个路径。 
             | 
| TreePath[] | getSelectionPaths()
              返回选择中的路径。 
             | 
| int[] | getSelectionRows()
              返回当前选定的所有行。 
             | 
| boolean | isPathSelected(TreePath path)
              如果路径 
              path在当前选择中,则返回true。 | 
| boolean | isRowSelected(int row)
              如果选择了 
              row的行,则返回true。 | 
| boolean | isSelectionEmpty()
              如果选择当前为空,则返回true。 
             | 
| void | removePropertyChangeListener(PropertyChangeListener listener)
              从侦听器列表中移除PropertyChangeListener。 
             | 
| void | removeSelectionPath(TreePath path)
              从选择中删除路径。 
             | 
| void | removeSelectionPaths(TreePath[] paths)
              从选择中删除路径。 
             | 
| void | removeTreeSelectionListener(TreeSelectionListener x)
              从每次所选树形路径组更改时通知的侦听器列表中删除x。 
             | 
| void | resetRowSelection()
              将此对象的映射从TreePath更新为行。 
             | 
| void | setRowMapper(RowMapper newMapper)
              设置RowMapper实例。 
             | 
| void | setSelectionMode(int mode)
              设置选择模型,它必须是SINGLE_TREE_SELECTION,CONTIGUOUS_TREE_SELECTION或DISCONTIGUOUS_TREE_SELECTION之一。 
             | 
| void | setSelectionPath(TreePath path)
              将选择设置为路径。 
             | 
| void | setSelectionPaths(TreePath[] paths)
              将选择设置为路径。 
             | 
static final int SINGLE_TREE_SELECTION
static final int CONTIGUOUS_TREE_SELECTION
static final int DISCONTIGUOUS_TREE_SELECTION
void setSelectionMode(int mode)
 如果当前选择对新模式无效,这可能会更改选择。 例如,如果在模式更改为SINGLE_TREE_SELECTION时选择了三个TreePath,则只保留一个TreePath。 确定什么TreePath保持选择是由特定的实现决定的。 
int getSelectionMode()
SINGLE_TREE_SELECTION , 
           CONTIGUOUS_TREE_SELECTION或 
           DISCONTIGUOUS_TREE_SELECTION 。 
          void setSelectionPath(TreePath path)
path为null,则与调用clearSelection具有相同的效果。 
          path - 要选择的新路径 
           void setSelectionPaths(TreePath[] paths)
paths为null,则与调用clearSelection具有相同的效果。 
          paths - 新的选择 
           void addSelectionPath(TreePath path)
path为空,则无效。 
          path - 添加到当前选择的新路径 
           void addSelectionPaths(TreePath[] paths)
paths为空,则无效。 
          paths - 添加到当前选择的新路径 
           void removeSelectionPath(TreePath path)
path为空,则path 。 
          path - 从选择中删除的路径 
           void removeSelectionPaths(TreePath[] paths)
paths中的任何路径, paths通知TreeSelectionListeners。 
           如果paths为空,则此方法无效。 
          paths - 从选择中删除的路径 
           TreePath getSelectionPath()
RowMapper 。 
          TreePath[] getSelectionPaths()
int getSelectionCount()
boolean isPathSelected(TreePath path)
path位于当前选择中,则返回true。 
          boolean isSelectionEmpty()
void clearSelection()
void setRowMapper(RowMapper newMapper)
RowMapper getRowMapper()
int[] getSelectionRows()
int getMinSelectionRow()
int getMaxSelectionRow()
boolean isRowSelected(int row)
row的行,则返回true。 
          void resetRowSelection()
你一般不用这样叫; JTree及其相关的监听器将为您调用。 如果您正在实现自己的视图类,那么您将必须调用此视图。
int getLeadSelectionRow()
TreePath getLeadSelectionPath()
void addPropertyChangeListener(PropertyChangeListener listener)
当选择模式更改时,PropertyChangeEvent将被触发。
listener - 要添加的PropertyChangeListener 
           void removePropertyChangeListener(PropertyChangeListener listener)
listener - 要删除的PropertyChangeListener 
           void addTreeSelectionListener(TreeSelectionListener x)
x - 要添加的新侦听器 
           void removeTreeSelectionListener(TreeSelectionListener x)
x - 要删除的侦听器 
            Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.