|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JList stanford.cs106.gui.JStringList
public class JStringList
Represents a list of strings with optional colors.
Constructor Summary | |
---|---|
JStringList()
Constructs a new empty list of strings. |
Method Summary | |
---|---|
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. |
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, or null if no string is selected. |
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. |
Methods inherited from class javax.swing.JList |
---|
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, 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, updateUI |
Methods inherited from class javax.swing.JComponent |
---|
addAncestorListener, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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, update |
Methods inherited from class java.awt.Container |
---|
add, 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, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
action, 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, hide, 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, transferFocusUpCycle |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public JStringList()
Method Detail |
---|
public void addActionListener(ActionListener listener)
listener
- the listener to attach
NullPointerException
- if the listener is null.public void addItem(String s)
s
- the string to add
NullPointerException
- if s is null.public void addItem(String s, Color color)
s
- the string to addcolor
- the color in which to display the text
NullPointerException
- 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 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()
getModel
in class javax.swing.JList
public String getSelectedValue()
getSelectedValue
in class javax.swing.JList
public Color getSelectedValueColor()
public void removeActionListener(ActionListener listener)
listener
- the listener to detach
NullPointerException
- if the listener is null.public void removeItem(int index)
index
- the index from which to remove
ArrayIndexOutOfBoundsException
- If the index is outside the range of this list (0 .. size-1).public void removeItem(String s)
s
- the string to remove
NullPointerException
- 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.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |