DESY ACOP Beans Home

com.cosylab.gui.components
Class SimpleComboBox

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JComboBox
                  extended by com.cosylab.gui.components.SimpleComboBox
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ListDataListener
Direct Known Subclasses:
ColorEditor, FontEditor

public class SimpleComboBox
extends javax.swing.JComboBox

A simple implementation of a combo box that provides several display styles through different javax.swing.plaf.ComboBoxUI implementations. These can be set through setStyle(int) method and are enumerated as: SIMPLE_STYLE displays no button in the comboBox. Items are selected from a drop down list activated on mouseclick. DROP_DOWN_STYLE displays an arrowed button on the right side of the combo box that activates the drop down list. SWITCH_STYLE_POPUP_ENABLED positions two buttons on each side of the combo box that can be used to switch between items of the combo box, while the complete list of items can still be accesed by mouseclick on the selected item cell. SWITCH_STYLE_POPUP_DISABLED has the same features as SWITCH_STYLE_POPUP_ENABLED but the drop-down list is no longer available to the user. The method setUI(javax.swing.plaf.ComboBoxUI) has been overrriden to accept only SimpleComboBoxUI instances. In addition SimpleComboBox accepts custom renderer to be set to rendere only the selected item cell differently from all the other items in the drop-down list. This renderer can be set through setSelectedItemRenderer(ListCellRenderer). If null, the default renderer is used.

Version:
$id$
Author:
Jernej Kamenik
See Also:
Serialized Form

Nested Class Summary
static class SimpleComboBox.DropComboBoxUI
          This extension of SimpleComboBoxUI uses the standard right-side arrow button to activate the drop-down list.
static class SimpleComboBox.SimpleComboBoxUI
          The simplest implementation od ComboBoxUI displays no button in the comboBox.
static class SimpleComboBox.Style
           
static class SimpleComboBox.SwitchComboBoxUI
           
 
Nested classes/interfaces inherited from class javax.swing.JComboBox
javax.swing.JComboBox.AccessibleJComboBox, javax.swing.JComboBox.KeySelectionManager
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int DROP_DOWN_STYLE
          Deprecated.  
static int SIMPLE_STYLE
          Deprecated.  
static int SWITCH_STYLE_POPUP_DISABLED
          Deprecated.  
static int SWITCH_STYLE_POPUP_ENABLED
          Deprecated.  
 
Fields inherited from class javax.swing.JComboBox
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SimpleComboBox()
          Constructor for SimpleComboBox.
SimpleComboBox(javax.swing.ComboBoxModel aModel)
          Constructor for SimpleComboBox.
SimpleComboBox(java.lang.Object[] items)
          Constructor for SimpleComboBox.
SimpleComboBox(java.util.Vector items)
          Constructor for SimpleComboBox.
 
Method Summary
 javax.swing.ListCellRenderer getSelectedItemRenderer()
          Returns the selectedItemRenderer.
 int getStyle()
          Returns the style.
static void main(java.lang.String[] args)
          For testing and demonstration purposes only.
 void setEnabled(boolean b)
           
 void setSelectedItemRenderer(javax.swing.ListCellRenderer newSelectedItemRenderer)
          Sets the selectedItemRenderer.
 void setStyle(int newStyle)
          Deprecated. use setStyle(Style)
 void setStyle(SimpleComboBox.Style newStyleE)
           
 void setUI(javax.swing.plaf.ComboBoxUI ui)
          This method has been overriden to enforce usage of SimpleComboBoxUI.
 
Methods inherited from class javax.swing.JComboBox
actionPerformed, actionPropertyChanged, addActionListener, addItem, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditable, setEditor, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setPrototypeDisplayValue, setRenderer, setSelectedIndex, setSelectedItem, showPopup, 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, 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, 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, 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SIMPLE_STYLE

public static int SIMPLE_STYLE
Deprecated. 

DROP_DOWN_STYLE

public static int DROP_DOWN_STYLE
Deprecated. 

SWITCH_STYLE_POPUP_ENABLED

public static int SWITCH_STYLE_POPUP_ENABLED
Deprecated. 

SWITCH_STYLE_POPUP_DISABLED

public static int SWITCH_STYLE_POPUP_DISABLED
Deprecated. 
Constructor Detail

SimpleComboBox

public SimpleComboBox(javax.swing.ComboBoxModel aModel)
Constructor for SimpleComboBox.

Parameters:
aModel -
See Also:
JComboBox.JComboBox(ComboBoxModel)

SimpleComboBox

public SimpleComboBox(java.lang.Object[] items)
Constructor for SimpleComboBox.

Parameters:
items -
See Also:
JComboBox.JComboBox(Object[])

SimpleComboBox

public SimpleComboBox(java.util.Vector items)
Constructor for SimpleComboBox.

Parameters:
items -
See Also:
JComboBox.JComboBox(Vector)

SimpleComboBox

public SimpleComboBox()
Constructor for SimpleComboBox.

See Also:
JComboBox.JComboBox()
Method Detail

setUI

public void setUI(javax.swing.plaf.ComboBoxUI ui)
This method has been overriden to enforce usage of SimpleComboBoxUI.

Overrides:
setUI in class javax.swing.JComboBox
Parameters:
ui - ComboBoxUI
See Also:
JComboBox.setUI(ComboBoxUI)

getSelectedItemRenderer

public javax.swing.ListCellRenderer getSelectedItemRenderer()
Returns the selectedItemRenderer.

Returns:
ListCellRenderer

setEnabled

public void setEnabled(boolean b)
Overrides:
setEnabled in class javax.swing.JComboBox

setSelectedItemRenderer

public void setSelectedItemRenderer(javax.swing.ListCellRenderer newSelectedItemRenderer)
Sets the selectedItemRenderer.

Parameters:
newSelectedItemRenderer - The selectedItemRenderer to set. If null, the selected item is rendered with the common list cell renderer of the combo box.
See Also:
JComboBox.setRenderer(ListCellRenderer)

getStyle

public int getStyle()
Returns the style.

Returns:
int

setStyle

public void setStyle(SimpleComboBox.Style newStyleE)

setStyle

public void setStyle(int newStyle)
Deprecated. use setStyle(Style)

Sets the style. SIMPLE_STYLE only displays the selected item. When clicked the drop down list dialog shows up. SWITCH_STYLE_POPUP_DISABLED displays the selected item together with two arrowed buttons on each style to switch between adjacent items in the list. No popup is displayed. SWITCH_STYLE_POPUP_ENABLED is the same as SWITCH_STYLE_POPUP_DISABLED only that at mouse click the drop down list of items is displayed. DROP_DOWN_STYLE displays the SimpleComboBox in conventional way. The selected item is displyed next to a downwards pointing arrow button which brings up the drop down list of all items.

Parameters:
newStyle - int the style to be used by this SimpleComboBox

main

public static void main(java.lang.String[] args)
For testing and demonstration purposes only.

Parameters:
args - String[]


Copyright © 2010. All Rights Reserved.