TreeSelectionEvent (Java Platform SE 8 ) (original) (raw)
- java.util.EventObject
- javax.swing.event.TreeSelectionEvent
All Implemented Interfaces:
Serializable
public class TreeSelectionEvent
extends EventObject
An event that characterizes a change in the current selection. The change is based on any number of paths. TreeSelectionListeners will generally query the source of the event for the new selected status of each potentially changed row.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans™ has been added to the java.beans
package. Please see XMLEncoder.
See Also:
TreeSelectionListener, TreeSelectionModel
Field Summary
Fields
Modifier and Type Field Description protected boolean[] areNew For each path identifies if that path is in fact new. protected TreePath newLeadSelectionPath leadSelectionPath after the paths changed, may be null. protected TreePath oldLeadSelectionPath leadSelectionPath before the paths changed, may be null. protected TreePath[] paths Paths this event represents. * ### Fields inherited from class java.util.[EventObject](../../../java/util/EventObject.html "class in java.util") `[source](../../../java/util/EventObject.html#source)`
Constructor Summary
Constructors
Constructor Description TreeSelectionEvent(Object source,TreePath[] paths, boolean[] areNew,TreePath oldLeadSelectionPath,TreePath newLeadSelectionPath) Represents a change in the selection of a TreeSelectionModel. TreeSelectionEvent(Object source,TreePath path, boolean isNew,TreePath oldLeadSelectionPath,TreePath newLeadSelectionPath) Represents a change in the selection of a TreeSelectionModel. Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type Method Description Object cloneWithSource(Object newSource) Returns a copy of the receiver, but with the source being newSource. TreePath getNewLeadSelectionPath() Returns the current lead path. TreePath getOldLeadSelectionPath() Returns the path that was previously the lead path. TreePath getPath() Returns the first path element. TreePath[] getPaths() Returns the paths that have been added or removed from the selection. boolean isAddedPath() Returns whether the path identified by getPath was added to the selection. boolean isAddedPath(int index) Returns whether the path at getPaths()[index] was added to the selection. boolean isAddedPath(TreePath path) Returns whether the specified path was added to the selection. * ### Methods inherited from class java.util.[EventObject](../../../java/util/EventObject.html "class in java.util") `[getSource](../../../java/util/EventObject.html#getSource--), [toString](../../../java/util/EventObject.html#toString--)` * ### Methods inherited from class java.lang.[Object](../../../java/lang/Object.html "class in java.lang") `[clone](../../../java/lang/Object.html#clone--), [equals](../../../java/lang/Object.html#equals-java.lang.Object-), [finalize](../../../java/lang/Object.html#finalize--), [getClass](../../../java/lang/Object.html#getClass--), [hashCode](../../../java/lang/Object.html#hashCode--), [notify](../../../java/lang/Object.html#notify--), [notifyAll](../../../java/lang/Object.html#notifyAll--), [wait](../../../java/lang/Object.html#wait--), [wait](../../../java/lang/Object.html#wait-long-), [wait](../../../java/lang/Object.html#wait-long-int-)`
Field Detail
* #### paths protected [TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree")[] paths Paths this event represents. * #### areNew protected boolean[] areNew For each path identifies if that path is in fact new. * #### oldLeadSelectionPath protected [TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree") oldLeadSelectionPath leadSelectionPath before the paths changed, may be null. * #### newLeadSelectionPath protected [TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree") newLeadSelectionPath leadSelectionPath after the paths changed, may be null.
Constructor Detail
* #### TreeSelectionEvent public TreeSelectionEvent([Object](../../../java/lang/Object.html "class in java.lang") source, [TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree")[] paths, boolean[] areNew, [TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree") oldLeadSelectionPath, [TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree") newLeadSelectionPath) Represents a change in the selection of a TreeSelectionModel. paths identifies the paths that have been either added or removed from the selection. Parameters: `source` \- source of event `paths` \- the paths that have changed in the selection * #### TreeSelectionEvent public TreeSelectionEvent([Object](../../../java/lang/Object.html "class in java.lang") source, [TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree") path, boolean isNew, [TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree") oldLeadSelectionPath, [TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree") newLeadSelectionPath) Represents a change in the selection of a TreeSelectionModel. path identifies the path that have been either added or removed from the selection. Parameters: `source` \- source of event `path` \- the path that has changed in the selection `isNew` \- whether or not the path is new to the selection, false means path was removed from the selection.
Method Detail
* #### getPaths public [TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree")[] getPaths() Returns the paths that have been added or removed from the selection. * #### getPath public [TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree") getPath() Returns the first path element. * #### isAddedPath public boolean isAddedPath() Returns whether the path identified by `getPath` was added to the selection. A return value of `true` indicates the path identified by `getPath` was added to the selection. A return value of `false` indicates `getPath` was selected, but is no longer selected. Returns: `true` if `getPath` was added to the selection,`false` otherwise * #### isAddedPath public boolean isAddedPath([TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree") path) Returns whether the specified path was added to the selection. A return value of `true` indicates the path identified by`path` was added to the selection. A return value of`false` indicates `path` is no longer selected. This method is only valid for the paths returned from `getPaths()`; invoking with a path not included in `getPaths()` throws an`IllegalArgumentException`. Parameters: `path` \- the path to test Returns: `true` if `path` was added to the selection,`false` otherwise Throws: `[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if `path` is not contained in `getPaths` See Also: [getPaths()](../../../javax/swing/event/TreeSelectionEvent.html#getPaths--) * #### isAddedPath public boolean isAddedPath(int index) Returns whether the path at `getPaths()[index]` was added to the selection. A return value of `true` indicates the path was added to the selection. A return value of `false` indicates the path is no longer selected. Parameters: `index` \- the index of the path to test Returns: `true` if the path was added to the selection,`false` otherwise Throws: `[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if index is outside the range of`getPaths` Since: 1.3 See Also: [getPaths()](../../../javax/swing/event/TreeSelectionEvent.html#getPaths--) * #### getOldLeadSelectionPath public [TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree") getOldLeadSelectionPath() Returns the path that was previously the lead path. * #### getNewLeadSelectionPath public [TreePath](../../../javax/swing/tree/TreePath.html "class in javax.swing.tree") getNewLeadSelectionPath() Returns the current lead path. * #### cloneWithSource public [Object](../../../java/lang/Object.html "class in java.lang") cloneWithSource([Object](../../../java/lang/Object.html "class in java.lang") newSource) Returns a copy of the receiver, but with the source being newSource.
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, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.