public class DefaultTreeSelectionModel extends Object implements Cloneable, Serializable, TreeSelectionModel
从更新所选路径的任何方法调用resetRowSelection。 如果您将任何这些方法子类化以过滤允许被选择的内容,请确保并消息resetRowSelection如果您不发送超级消息。 警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已经添加到java.beans包中。 请参阅XMLEncoder 。
JTree
| Modifier and Type | Field and Description |
|---|---|
protected SwingPropertyChangeSupport |
changeSupport
用于发送已注册的听众。
|
protected int |
leadIndex
引导路径的索引在选择。
|
protected TreePath |
leadPath
添加的最后路径
|
protected int |
leadRow
铅排。
|
protected EventListenerList |
listenerList
事件侦听器列表。
|
protected DefaultListSelectionModel |
listSelectionModel
处理维护列表选择模型。
|
protected RowMapper |
rowMapper
为给定的路径提供一行。
|
protected TreePath[] |
selection
当前选择的路径。
|
static String |
SELECTION_MODE_PROPERTY
selectionMode的属性名称。
|
protected int |
selectionMode
选择的模式将是SINGLE_TREE_SELECTION,CONTIGUOUS_TREE_SELECTION或DISCONTIGUOUS_TREE_SELECTION。
|
CONTIGUOUS_TREE_SELECTION, DISCONTIGUOUS_TREE_SELECTION, SINGLE_TREE_SELECTION| Constructor and Description |
|---|
DefaultTreeSelectionModel()
创建一个新的DefaultTreeSelectionModel实例,该实例为空,选择模式为DISCONTIGUOUS_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集合更改时通知的侦听器列表。
|
protected boolean |
arePathsContiguous(TreePath[] paths)
如果路径是连续的,或者该对象没有RowMapper,则返回true。
|
protected boolean |
canPathsBeAdded(TreePath[] paths)
用于测试是否可以添加一组
TreePath 。
|
protected boolean |
canPathsBeRemoved(TreePath[] paths)
如果可以删除路径而不会破坏模型的连续性,则返回true。
|
void |
clearSelection()
清空当前的选择。
|
Object |
clone()
返回具有相同选择的此对象的克隆。
|
protected void |
fireValueChanged(TreeSelectionEvent e)
通知所有在此对象上注册树选择事件的侦听器。
|
TreePath |
getLeadSelectionPath()
返回添加的最后一个路径。
|
int |
getLeadSelectionRow()
返回引导选择索引。
|
<T extends EventListener> |
getListeners(类<T> listenerType)
在此模型上返回当前注册为
FooListener的所有对象的数组。
|
int |
getMaxSelectionRow()
返回从当前所选TreePath集合的RowMapper获取的最大值。
|
int |
getMinSelectionRow()
返回从当前所选TreePath集合的RowMapper获取的最小值。
|
PropertyChangeListener[] |
getPropertyChangeListeners()
返回在此
DefaultTreeSelectionModel上
DefaultTreeSelectionModel的所有属性更改侦听器的
DefaultTreeSelectionModel 。
|
RowMapper |
getRowMapper()
返回能够将TreePath映射到行的RowMapper实例。
|
int |
getSelectionCount()
返回所选路径的数量。
|
int |
getSelectionMode()
返回选择模式,一个
SINGLE_TREE_SELECTION ,
DISCONTIGUOUS_TREE_SELECTION或
CONTIGUOUS_TREE_SELECTION 。
|
TreePath |
getSelectionPath()
返回选择中的第一个路径。
|
TreePath[] |
getSelectionPaths()
返回选择。
|
int[] |
getSelectionRows()
以行为单位返回选择。
|
TreeSelectionListener[] |
getTreeSelectionListeners()
返回在此模型上注册的所有树选择侦听器的数组。
|
protected void |
insureRowContinuity()
确保当前选择的
TreePath在当前选择模式下有效。
|
protected void |
insureUniqueness()
这种方法已经过时了,它的实现现在是一个noop。
|
boolean |
isPathSelected(TreePath path)
如果路径
path在当前选择中,则返回true。
|
boolean |
isRowSelected(int row)
如果选择了
row的行,则返回true。
|
boolean |
isSelectionEmpty()
如果选择当前为空,则返回true。
|
protected void |
notifyPathChange(Vector<?> changedPaths, TreePath oldLeadSelection)
已弃用
从JDK版本1.7开始
|
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[] pPaths)
设置选择。
|
String |
toString()
返回显示和标识此对象属性的字符串。
|
protected void |
updateLeadIndex()
更新leadIndex实例变量。
|
public static final String SELECTION_MODE_PROPERTY
protected SwingPropertyChangeSupport changeSupport
protected TreePath[] selection
protected EventListenerList listenerList
protected transient RowMapper rowMapper
protected DefaultListSelectionModel listSelectionModel
protected int selectionMode
protected TreePath leadPath
protected int leadIndex
protected int leadRow
public DefaultTreeSelectionModel()
public void setRowMapper(RowMapper newMapper)
setRowMapper在接口
TreeSelectionModel
public RowMapper getRowMapper()
getRowMapper在界面
TreeSelectionModel
public void setSelectionMode(int mode)
DISCONTIGUOUS_TREE_SELECTION 。
如果当前选择对新模式无效,这可能会更改选择。 例如,如果在模式更改为SINGLE_TREE_SELECTION时选择了三个TreePath,则只保留一个TreePath。 确定什么TreePath保持选择是由特定的实现决定的。
将模式设置为定义类型以外的模式将导致模式变为DISCONTIGUOUS_TREE_SELECTION 。
setSelectionMode在接口
TreeSelectionModel
public int getSelectionMode()
SINGLE_TREE_SELECTION ,
DISCONTIGUOUS_TREE_SELECTION或
CONTIGUOUS_TREE_SELECTION 。
getSelectionMode在接口
TreeSelectionModel
public void setSelectionPath(TreePath path)
path为null,则与调用clearSelection具有相同的效果。
setSelectionPath在界面
TreeSelectionModel
path - 选择的新路径
public void setSelectionPaths(TreePath[] pPaths)
null或为空,则清除选择。
如果选择模式是SINGLE_TREE_SELECTION ,仅在第一路径pPaths使用。
如果选择模式为CONTIGUOUS_TREE_SELECTION ,并且提供的路径不连续,则仅使用pPaths中的第一个路径。
如果选择模式为DISCONTIGUOUS_TREE_SELECTION ,则使用所有路径。
所有null在路径pPaths被忽略。
如果这是一个变更,所有注册的TreeSelectionListener都被通知。
引导路径设置为最后唯一的路径。
从getSelectionPaths返回的路径与提供给此方法的顺序相同。
setSelectionPaths在接口
TreeSelectionModel
pPaths - 新的选择
public void addSelectionPath(TreePath path)
path为空,则无效。
addSelectionPath在界面
TreeSelectionModel
path - 添加到当前选择的新路径
public void addSelectionPaths(TreePath[] paths)
paths为空,则无效。
引导路径设置为paths中的最后一个元素。
如果选择模式为CONTIGUOUS_TREE_SELECTION ,并添加新路径将使选择不连续。 那么可以导致两件事情:如果paths中的paths是连续的,则选择将成为这些TreePath, paths TreePath不是连续的,并且选择将成为paths中的第一个TreePath。
addSelectionPaths在界面
TreeSelectionModel
paths - 添加到当前选择的新路径
public void removeSelectionPath(TreePath path)
path为空,则无效。
removeSelectionPath在界面
TreeSelectionModel
path - 从选择中删除的路径
public void removeSelectionPaths(TreePath[] paths)
paths为空,则无效。
removeSelectionPaths在界面
TreeSelectionModel
paths - 从选择中删除的路径
public TreePath getSelectionPath()
getSelectionPath在界面
TreeSelectionModel
public TreePath[] getSelectionPaths()
getSelectionPaths在接口
TreeSelectionModel
public int getSelectionCount()
getSelectionCount在接口
TreeSelectionModel
public boolean isPathSelected(TreePath path)
path位于当前选择中,则返回true。
isPathSelected在界面
TreeSelectionModel
public boolean isSelectionEmpty()
isSelectionEmpty在接口
TreeSelectionModel
public void clearSelection()
clearSelection在界面
TreeSelectionModel
public void addTreeSelectionListener(TreeSelectionListener x)
addTreeSelectionListener在接口
TreeSelectionModel
x - 要添加的新侦听器
public void removeTreeSelectionListener(TreeSelectionListener x)
removeTreeSelectionListener在接口
TreeSelectionModel
x - 要删除的侦听器
public TreeSelectionListener[] getTreeSelectionListeners()
TreeSelectionListener或一个空数组,如果没有树选择监听器当前注册
addTreeSelectionListener(javax.swing.event.TreeSelectionListener) ,
removeTreeSelectionListener(javax.swing.event.TreeSelectionListener)
protected void fireValueChanged(TreeSelectionEvent e)
public <T extends EventListener> T[] getListeners(类<T> listenerType)
FooListener的所有对象的数组。
FooListener使用addFooListener 。
您可以使用类文字指定listenerType参数,例如FooListener.class 。 例如,您可以使用以下代码查询DefaultTreeSelectionModel m其树选择侦听器:
TreeSelectionListener[] tsls = (TreeSelectionListener[])(m.getListeners(TreeSelectionListener.class));
如果没有这样的侦听器存在,这个方法返回一个空数组。
listenerType - 所请求的听众的类型;
此参数应指定从java.util.EventListener下降的java.util.EventListener
FooListener的所有对象的数组,如果没有添加此类侦听器,则为空数组
ClassCastException - 如果
listenerType没有指定实现java.util.EventListener的类或
java.util.EventListener
getTreeSelectionListeners() ,
getPropertyChangeListeners()
public int[] getSelectionRows()
getSelectionPaths返回的getSelectionPaths和这种方法之间TreePath是一对一的映射。
特别是,如果TreePath不可见( RowMapper返回-1对应的行TreePath ),则相应的行不包括在返回的数组中。
例如,如果选择由两个路径组成, A和B ,在A行10和B不可见的B,则该方法返回一个具有单个条目10的数组。
getSelectionRows在界面
TreeSelectionModel
public int getMinSelectionRow()
getMinSelectionRow在界面
TreeSelectionModel
public int getMaxSelectionRow()
getMaxSelectionRow在接口
TreeSelectionModel
public boolean isRowSelected(int row)
row的行,则返回true。
isRowSelected在界面
TreeSelectionModel
public void resetRowSelection()
通常不需要调用它,JTree及其关联的侦听器将为您调用。 如果你正在实现自己的View类,那么你将不得不调用这个。
这将调用insureRowContinuity以确保当前选择的TreePaths基于选择模式仍然有效。
resetRowSelection在界面
TreeSelectionModel
public int getLeadSelectionRow()
getLeadSelectionRow在界面
TreeSelectionModel
public TreePath getLeadSelectionPath()
getLeadSelectionPath在界面
TreeSelectionModel
public void addPropertyChangeListener(PropertyChangeListener listener)
当选择模式更改时,PropertyChangeEvent将被触发。
addPropertyChangeListener在界面
TreeSelectionModel
listener - 要添加的PropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
removePropertyChangeListener在界面
TreeSelectionModel
listener - 要删除的PropertyChangeListener
public PropertyChangeListener[] getPropertyChangeListeners()
DefaultTreeSelectionModel上
DefaultTreeSelectionModel的所有属性更改侦听器的
DefaultTreeSelectionModel 。
PropertyChangeListener s或一个空数组,如果没有属性更改侦听器当前注册
addPropertyChangeListener(java.beans.PropertyChangeListener) ,
removePropertyChangeListener(java.beans.PropertyChangeListener)
protected void insureRowContinuity()
TreePath在当前选择模式下有效。
如果选择模式为CONTIGUOUS_TREE_SELECTION ,并且存在RowMapper ,则将确保所有行都是连续的,也就是说,当排序所有行按顺序排列时,无间隙。
如果选择不连续,则选择将重置为包含连续行排序时的第一组。
如果选择模式为SINGLE_TREE_SELECTION ,并且选择了多个TreePath,则选择将重置为包含当前选择的第一个路径。
protected boolean arePathsContiguous(TreePath[] paths)
protected boolean canPathsBeAdded(TreePath[] paths)
TreePath 。
如果paths为空(或空),或此对象没有RowMapper,或者当前没有选择任何内容,或选择模式为DISCONTIGUOUS_TREE_SELECTION ,或者添加到当前选择的路径仍然会产生一个连续的TreePath s集合,则TreePath 。
protected boolean canPathsBeRemoved(TreePath[] paths)
@Deprecated protected void notifyPathChange(Vector<?> changedPaths, TreePath oldLeadSelection)
protected void updateLeadIndex()
protected void insureUniqueness()
public Object clone() throws CloneNotSupportedException
clone在
Object
CloneNotSupportedException - 从不会被这个类的实例抛出
Cloneable
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.