|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent | +--javax.swing.JComboBox | +--jas.util.JASEditableComboBox
This class is ideal if you want to have a text field for user input but also have a list of recently selected items available to choose from. Some notes on using this class:
clickDefault
is true
. This behaviour may be desirable because
the default button is normally "clicked" when the user clicks on
the "Enter" key, but this behaviour doesn't normally happen unless
you add an ActionListener to the text field.addActionListener(ActionListener)
on this
object causes the ActionListener to be added to the text field.Basically, a ChangeEvent is a dual purpose event. One is sent to listeners both when a KeyEvent is generated from the text field, and one is sent when an ItemEvent is generated (which happens when an item is selected from the drop-down list). This means that somebody who wants to know when the actual text showing has changed only needs to implement ChangeListener instead of both ItemListener and KeyListener.
Inner classes inherited from class javax.swing.JComboBox |
javax.swing.JComboBox.AccessibleJComboBox, javax.swing.JComboBox.KeySelectionManager |
Inner classes inherited from class javax.swing.JComponent |
javax.swing.JComponent.AccessibleJComponent |
Inner classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
Inner classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent |
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 | |
JASEditableComboBox(java.lang.String[] dropDownItems,
boolean clickDefault)
Creates a JASEditableComboBox with the given list of drop-down items. |
|
JASEditableComboBox(java.lang.String key,
int nItems,
boolean clickDefault)
Creates a JASEditableComboBox with a dropDown list that will be stored in the UserProperties object for the Application. |
|
JASEditableComboBox(java.lang.String key,
java.lang.String lengthKey,
boolean clickDefault)
Creates a JASEditableComboBox with a dropDown list that will be stored in the UserProperties object for the Application. |
Method Summary | |
void |
addActionListener(java.awt.event.ActionListener l)
Adds an the given ActionListener to the text field. |
void |
addChangeListener(javax.swing.event.ChangeListener l)
Change listeners will be notified any time the text visible in the text field changes. |
void |
addKeyListener(java.awt.event.KeyListener kl)
Adds a key listener to the text field, not to the JComboBox. |
protected void |
fireItemStateChanged(java.awt.event.ItemEvent event)
This method is protected as an implementation side effect. |
java.awt.Dimension |
getMaximumSize()
Encorporates the maximum width if it has been set. |
java.awt.Dimension |
getMinimumSize()
Encorporates the minimum width if it has been set. |
java.awt.Dimension |
getPreferredSize()
Encorporates the minimum and maximum widths if they have been set. |
java.lang.String |
getText()
Returns the text currently showing in the text field. |
void |
keyPressed(java.awt.event.KeyEvent e)
This method is public as an implementation side effect; do not call. |
void |
keyReleased(java.awt.event.KeyEvent e)
This method is public as an implementation side effect; do not call. |
void |
keyTyped(java.awt.event.KeyEvent e)
This method is public as an implementation side effect; do not call. |
void |
requestFocus()
Requests focus for the text field of the box. |
void |
saveState()
If a key was supplied to the constructor, the drop-down list will be updated to include the currently selected item. |
void |
setMaxWidth(int maxWidth)
Set the maximum width of the box. |
void |
setMinWidth(int minWidth)
Set the minimum width of the box. |
void |
setText(java.lang.String s)
Sets the text showing in the text field. |
Methods inherited from class javax.swing.JComboBox |
actionPerformed, addItem, addItemListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, fireActionEvent, getAccessibleContext, getAction, getActionCommand, getEditor, getItemAt, getItemCount, getKeySelectionManager, getMaximumRowCount, getModel, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isFocusTraversable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditable, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setRenderer, setSelectedIndex, setSelectedItem, setUI, showPopup, updateUI |
Methods inherited from class javax.swing.JComponent |
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public JASEditableComboBox(java.lang.String[] dropDownItems, boolean clickDefault)
dropDownItems
- the items to show in the drop-down list (can safely be null
)clickDefault
- whether the default button should be clicked when Enter is pressedJRootPane.defaultButton
public JASEditableComboBox(java.lang.String key, int nItems, boolean clickDefault)
saveState()
method to have the list be updated to include the selected item.key
- the key that the drop-down items will be stored bynItems
- the maximum number of items that will be stored on the drop-down listclickDefault
- whether the default button should be clicked when Enter is pressedUserProperties
,
JRootPane.defaultButton
public JASEditableComboBox(java.lang.String key, java.lang.String lengthKey, boolean clickDefault)
saveState()
method to have the list be updated to include the selected item.key
- the key that the drop-down items will be stored bylengthKey
- the key that maps to the maximum number of items that will be stored on the drop-down listclickDefault
- whether the default button should be clicked when Enter is pressedUserProperties
,
JRootPane.defaultButton
Method Detail |
public void saveState()
public java.lang.String getText()
public void setText(java.lang.String s)
public void addKeyListener(java.awt.event.KeyListener kl)
addKeyListener
in class java.awt.Component
public final void keyReleased(java.awt.event.KeyEvent e)
keyReleased
in interface java.awt.event.KeyListener
public final void keyPressed(java.awt.event.KeyEvent e)
keyPressed
in interface java.awt.event.KeyListener
public void addChangeListener(javax.swing.event.ChangeListener l)
l
- the ChangeListener to addpublic void addActionListener(java.awt.event.ActionListener l)
addActionListener
in class javax.swing.JComboBox
protected final void fireItemStateChanged(java.awt.event.ItemEvent event)
fireItemStateChanged
in class javax.swing.JComboBox
public final void requestFocus()
requestFocus
in class javax.swing.JComponent
public final void keyTyped(java.awt.event.KeyEvent e)
keyTyped
in interface java.awt.event.KeyListener
public final void setMaxWidth(int maxWidth)
maxWidth
- give a number in pixels, or -1
to use defaultpublic final void setMinWidth(int minWidth)
minWidth
- give a number in pixels, or -1
to use defaultpublic final java.awt.Dimension getMaximumSize()
getMaximumSize
in class javax.swing.JComponent
setMaxWidth(int)
public final java.awt.Dimension getMinimumSize()
getMinimumSize
in class javax.swing.JComponent
setMinWidth(int)
public final java.awt.Dimension getPreferredSize()
getPreferredSize
in class javax.swing.JComponent
setMinWidth(int)
,
setMaxWidth(int)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |