public class JStringList extends JList
JList.AccessibleJList, JList.DropLocationJComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategyHORIZONTAL_WRAP, VERTICAL, VERTICAL_WRAPlistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JStringList()
Constructs a new empty list of strings.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addActionListener(ActionListener listener)
Attaches the given listener to this list of strings so that it will be
notified when the user clicks on items in the list.
|
void |
addItem(String s)
Appends the given string to the end of this list, using the default black color.
|
void |
addItem(String s,
Color color)
Appends the given string to the end of this list, using the given color.
|
void |
addItems(String[] items)
Adds all of the items from the given array to this list, in black.
|
void |
addItems(String[] items,
Color[] colors)
Adds all of the items from the given array to this list, in the given colors.
|
void |
clear()
Removes all strings from this list.
|
String |
getActionCommand()
Returns the current action command of this list, which is the string that
will occur when action events are performed on this list.
|
ActionListener[] |
getActionListeners()
Returns an array of all action listeners currently listening to this list.
|
Color |
getColor(int index)
Returns the color of the item in the list at the given index.
|
String |
getItem(int index)
Returns the text of the item in the list at the given index.
|
int |
getItemCount()
Returns the number of items in the list.
|
DefaultListModel |
getModel()
Returns a reference to the underlying data model of this list.
|
String |
getSelectedValue()
Returns the string that is currently selected in this list.
|
Color |
getSelectedValueColor()
Returns the color of the string that is currently selected in this list.
|
void |
removeActionListener(ActionListener listener)
Detaches the given listener so that it will not be notified of future
action events that occur in this list.
|
void |
removeItem(int index)
Removes the element at the given index from this list, shifting others
down an index if necessary.
|
void |
removeItem(String s)
Removes the first occurrence of the given string element at the given index from this list, shifting others
down an index if necessary.
|
void |
setActionCommand(String actionCommand)
Sets the current action command of this list, which is the string that
will occur when action events are performed on this list.
|
void |
setColor(int index,
Color color)
Sets the color of the item at the given index to the given color.
|
void |
setColors(Color[] colors)
Sets the items of this list to use the colors from the given array.
|
void |
setItem(int index,
String s)
Sets the item at the given index to store the given text.
|
void |
setItem(int index,
String s,
Color color)
Sets the item at the given index to store the given text in the given color.
|
void |
setItems(String[] items,
Color[] colors)
Sets the list contents to be the given items in the given colors.
|
addListSelectionListener, addSelectionInterval, clearSelection, createSelectionModel, ensureIndexIsVisible, fireSelectionValueChanged, getAccessibleContext, getAnchorSelectionIndex, getCellBounds, getCellRenderer, getDragEnabled, getDropLocation, getDropMode, getFirstVisibleIndex, getFixedCellHeight, getFixedCellWidth, getLastVisibleIndex, getLayoutOrientation, getLeadSelectionIndex, getListSelectionListeners, getMaxSelectionIndex, getMinSelectionIndex, getNextMatch, getPreferredScrollableViewportSize, getPrototypeCellValue, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedIndex, getSelectedIndices, getSelectedValues, getSelectedValuesList, getSelectionBackground, getSelectionForeground, getSelectionMode, getSelectionModel, getToolTipText, getUI, getUIClassID, getValueIsAdjusting, getVisibleRowCount, indexToLocation, isSelectedIndex, isSelectionEmpty, locationToIndex, paramString, removeListSelectionListener, removeSelectionInterval, setCellRenderer, setDragEnabled, setDropMode, setFixedCellHeight, setFixedCellWidth, setLayoutOrientation, setListData, setListData, setModel, setPrototypeCellValue, setSelectedIndex, setSelectedIndices, setSelectedValue, setSelectionBackground, setSelectionForeground, setSelectionInterval, setSelectionMode, setSelectionModel, setUI, setValueIsAdjusting, setVisibleRowCount, updateUIaddAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateadd, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic void addActionListener(ActionListener listener)
listener - the listener to attachNullPointerException - if the listener is null.public void addItem(String s)
s - the string to addNullPointerException - if s is null.public void addItem(String s, Color color)
s - the string to addcolor - the color in which to display the textNullPointerException - if s or color are null.public void addItems(String[] items)
items - The array of items to add.NullPointerException - if the array or any of its elements is null.public void addItems(String[] items, Color[] colors)
items - The array of items to add.colors - The array of colors to use.NullPointerException - if either array or any of their elements is null.public void clear()
public String getActionCommand()
public ActionListener[] getActionListeners()
public Color getColor(int index)
index - the 0-based index of the item.ArrayIndexOutOfBoundsException - If the index is outside the range of this list (0 .. size-1).public String getItem(int index)
index - the 0-based index of the item.ArrayIndexOutOfBoundsException - If the index is outside the range of this list (0 .. size-1).public int getItemCount()
public DefaultListModel getModel()
public String getSelectedValue()
getSelectedValue in class JListpublic Color getSelectedValueColor()
public void removeActionListener(ActionListener listener)
listener - the listener to detachNullPointerException - if the listener is null.public void removeItem(int index)
index - the index from which to removeArrayIndexOutOfBoundsException - If the index is outside the range of this list (0 .. size-1).public void removeItem(String s)
s - the string to removeNullPointerException - if the listener is null.public void setActionCommand(String actionCommand)
actionCommand - the new command string to usepublic void setColor(int index,
Color color)
index - The index to modify.color - The color to put there.ArrayIndexOutOfBoundsException - If the index is outside the range of this list (0 .. size-1).NullPointerException - if the color is null.public void setColors(Color[] colors)
colors - The array of colors to use.NullPointerException - if the array or any of its elements is null.public void setItem(int index,
String s)
index - The index to modify.s - The text to put there.ArrayIndexOutOfBoundsException - If the index is outside the range of this list (0 .. size-1).NullPointerException - if s is null.public void setItem(int index,
String s,
Color color)
index - The index to modify.s - The text to put there.ArrayIndexOutOfBoundsException - If the index is outside the range of this list (0 .. size-1).NullPointerException - if s or color is null.public void setItems(String[] items, Color[] colors)
items - Array of items to add.colors - Array of colors to use for each item.NullPointerException - if either array or any of their elements is null.