public class ItemsSelector extends JPanel implements ActionListener, ListSelectionListener
Important the list of unselected objects is always
automatically sorted, therefore such objects must implement interface
Comparable
.
Note that the list of selected objects may be sorted by hand by the user.
JPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected static Object[] |
NO_ITEMS |
protected JButton |
selectButton |
protected JList<Object> |
selectedList |
protected JButton |
unselectButton |
protected JList<Object> |
unselectedList |
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
ItemsSelector(int rows,
int columns)
Constructs a selector pane having specified size and options.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent e)
Not part of the public API.
|
protected static Object[] |
appendItems(Object[] items,
Object[] added) |
protected void |
cancelSelectable() |
protected void |
cancelUnselectable() |
static Icon |
getDefaultIcon()
Returns the icon displayed by default by the selector dialog box.
|
Object[] |
getItems()
Returns the items contained in the the list of selected items.
|
protected static Object[] |
getItems(JList<Object> list) |
protected static Object[] |
getItems(JList<Object> list,
int[] indices) |
protected void |
itemsSelectable(int[] indices) |
protected void |
itemsUnselectable(int[] indices) |
static String |
joinItems(char separatorChar,
Object... items)
Equivalent to
joinItems(Character.toString(separatorChar), items) . |
static String |
joinItems(String separator,
Object... items)
Joins the string representations
(that is,
items[i].toString() )
of the specified list items using specified separator. |
protected static Object[] |
removeItems(Object[] items,
Object[] removed) |
protected void |
select() |
static Object[] |
selectItems(Component parentComponent,
String title,
ItemsSelector itemsSelector,
Icon icon,
String message)
All lower-level alternative to
selectItems(Component, String,
Object[], Object[]) . |
static Object[] |
selectItems(Component parentComponent,
String title,
Object[] allItems,
Object[] selectedItems)
Displays a dialog box containing a list of items.
|
void |
setItems(Object[] allItems,
Object[] selectedItems)
Populates the selector pane with items.
|
void |
setListCellRenderer(ListCellRenderer<Object> cellRenderer)
Specifies a custom renderer for use by both
the list of selected items and the list of unselected items.
|
protected static void |
setListData(JList<Object> list,
Object[] items) |
protected void |
unselect() |
void |
valueChanged(ListSelectionEvent e)
Not part of the public API.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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, 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, update
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, transferFocusDownCycle, validate, validateTree
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, 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, transferFocusUpCycle
protected JButton selectButton
protected JButton unselectButton
protected static final Object[] NO_ITEMS
public ItemsSelector(int rows, int columns)
rows
- number of visible rows of both lists (that is,
the list of selected items and the list of unselected items)columns
- number of visible columns of both listspublic void valueChanged(ListSelectionEvent e)
valueChanged
in interface ListSelectionListener
protected void itemsSelectable(int[] indices)
protected void itemsUnselectable(int[] indices)
protected void cancelUnselectable()
protected void cancelSelectable()
public void actionPerformed(ActionEvent e)
actionPerformed
in interface ActionListener
protected void select()
protected void unselect()
public void setListCellRenderer(ListCellRenderer<Object> cellRenderer)
public void setItems(Object[] allItems, Object[] selectedItems)
allItems
- the list of items to choose fromselectedItems
- suggested selection; may be null
public Object[] getItems()
public static Object[] selectItems(Component parentComponent, String title, Object[] allItems, Object[] selectedItems)
Unlike ItemChooserDialog
, this method can be used to select
multiple items from a list.
parentComponent
- the parent of dialog boxtitle
- the title of the dialog boxallItems
- the list of items to choose fromselectedItems
- suggested selection; may be null
null
if operation has been
canceled by userpublic static Icon getDefaultIcon()
public static Object[] selectItems(Component parentComponent, String title, ItemsSelector itemsSelector, Icon icon, String message)
selectItems(Component, String,
Object[], Object[])
.parentComponent
- the parent of dialog boxtitle
- the title of the dialog boxitemsSelector
- a selector pane already configured and
already populated with itemsicon
- an icon displayed at the left of itemsSelector.
May be null
.message
- a (possibly multi-line) message displayed
at the top of itemsSelector.
May be null
.null
if operation has been
canceled by userpublic static String joinItems(char separatorChar, Object... items)
joinItems(Character.toString(separatorChar), items)
.public static String joinItems(String separator, Object... items)
items[i].toString()
)
of the specified list items using specified separator.separator
- the string used to join itemsitems
- the list of items to be joined