javax.swing

Class DefaultSingleSelectionModel

public class DefaultSingleSelectionModel extends Object implements SingleSelectionModel, Serializable

The default implementation of {@link SingleSelectionModel}, used in {@link JTabbedPane}, {@link JMenuBar} and {@link JPopupMenu}.
Field Summary
protected ChangeEventchangeEvent
changeEvent
protected EventListenerListlistenerList
listenerList
Constructor Summary
DefaultSingleSelectionModel()
Creates a new DefaultSingleSelectionModel with no current selection.
Method Summary
voidaddChangeListener(ChangeListener listener)
Registers a listener to receive {@link ChangeEvent} notifications from this model whenever the selected index changes.
voidclearSelection()
Clears the selection by setting the selected index to -1 and sends a {@link ChangeEvent} to all registered listeners.
protected voidfireStateChanged()
fireStateChanged
ChangeListener[]getChangeListeners()
getChangeListeners
<T extends EventListener> T[]getListeners(Class<T> listenerClass)
getListeners
intgetSelectedIndex()
Returns the selected index or -1 if there is no selection.
booleanisSelected()
Returns true if there is a selection, and false otherwise.
voidremoveChangeListener(ChangeListener listener)
Deregisters a listener so that it no longer receives {@link ChangeEvent} notifications from this model.
voidsetSelectedIndex(int index)
Sets the selected index and, if this is different to the previous selection, sends a {@link ChangeEvent} to all registered listeners.

Field Detail

changeEvent

protected transient ChangeEvent changeEvent
changeEvent

listenerList

protected EventListenerList listenerList
listenerList

Constructor Detail

DefaultSingleSelectionModel

public DefaultSingleSelectionModel()
Creates a new DefaultSingleSelectionModel with no current selection.

Method Detail

addChangeListener

public void addChangeListener(ChangeListener listener)
Registers a listener to receive {@link ChangeEvent} notifications from this model whenever the selected index changes.

Parameters: listener the listener to add.

clearSelection

public void clearSelection()
Clears the selection by setting the selected index to -1 and sends a {@link ChangeEvent} to all registered listeners. If the selected index is already -1, this method does nothing.

fireStateChanged

protected void fireStateChanged()
fireStateChanged

getChangeListeners

public ChangeListener[] getChangeListeners()
getChangeListeners

Since: 1.4

getListeners

public <T extends EventListener> T[] getListeners(Class<T> listenerClass)
getListeners

Parameters: listenerClass the type fo listener

Returns: an array of listeners

Since: 1.3

getSelectedIndex

public int getSelectedIndex()
Returns the selected index or -1 if there is no selection.

Returns: The selected index.

See Also: DefaultSingleSelectionModel

isSelected

public boolean isSelected()
Returns true if there is a selection, and false otherwise.

Returns: A boolean.

removeChangeListener

public void removeChangeListener(ChangeListener listener)
Deregisters a listener so that it no longer receives {@link ChangeEvent} notifications from this model.

Parameters: listener the listener to remove.

setSelectedIndex

public void setSelectedIndex(int index)
Sets the selected index and, if this is different to the previous selection, sends a {@link ChangeEvent} to all registered listeners.

Parameters: index the index (use -1 to represent no selection).

See Also: getSelectedIndex DefaultSingleSelectionModel