javax.swing

Interface SingleSelectionModel

public interface SingleSelectionModel

A data model that is used in components that support at most one selected element, like {@link JTabbedPane}, {@link JMenu} and {@link JPopupMenu}.
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.
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.

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.

getSelectedIndex

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

Returns: The selected index.

See Also: SingleSelectionModel

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 SingleSelectionModel