public class RecentItemTextField extends JComboBox
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.
JComboBox.KeySelectionManager
JComponent.AccessibleJComponent
Component.BaselineResizeBehavior
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
RecentItemTextField() |
RecentItemTextField(String[] dropDownItems,
boolean clickDefault)
Creates a RecentItemTextField with the given list of drop-down items.
|
RecentItemTextField(String key,
int nItems,
boolean clickDefault)
Creates a RecentItemTextField with a dropDown list that will be stored in
the user properties object for the Application.
|
RecentItemTextField(String key,
String lengthKey,
boolean clickDefault)
Creates a RecentItemTextField with a dropDown list that will be stored in
the user properties object for the Application.
|
Modifier and Type | Method and Description |
---|---|
void |
addActionListener(ActionListener l)
Adds an the given ActionListener to the text field.
|
void |
addChangeListener(ChangeListener l)
Change listeners will be notified any time the text visible in the text
field changes.
|
void |
addKeyListener(KeyListener kl) |
String |
getKey()
Getter for property key.
|
Dimension |
getMaximumSize()
Incorporates the maximum width if it has been set.
|
Dimension |
getMinimumSize()
Incorporates the minimum width if it has been set.
|
int |
getNumberOfItems()
Getter for property numberOfItems.
|
Dimension |
getPreferredSize()
Incorporates the minimum and maximum widths if they have been set.
|
String |
getText()
Returns the text currently showing in the text field.
|
boolean |
isClickDefault()
Getter for property clickDefault.
|
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 |
setClickDefault(boolean clickDefault)
Setter for property clickDefault.
|
void |
setKey(String key)
Setter for property key.
|
void |
setMaxWidth(int maxWidth)
Set the maximum width of the box.
|
void |
setMinWidth(int minWidth)
Set the minimum width of the box.
|
void |
setNumberOfItems(int numberOfItems)
Setter for property numberOfItems.
|
void |
setText(String s)
Sets the text showing in the text field.
|
static String |
showInputDialog(Component owner,
Object message,
String key)
Show an input dialog, with a record of recent entries.
|
static String |
showInputDialog(Component owner,
Object message,
String title,
int messageType,
String key)
Show an input dialog, with a record of recent entries.
|
actionPerformed, addItem, addItemListener, addPopupMenuListener, configureEditor, contentsChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectWithKeyChar, setAction, setActionCommand, setEditable, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setPrototypeDisplayValue, setRenderer, setSelectedIndex, setSelectedItem, setUI, showPopup, updateUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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
public RecentItemTextField()
public RecentItemTextField(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 RecentItemTextField(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 pressedApplication.getUserProperties()
,
JRootPane.defaultButton
public RecentItemTextField(String key, 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 pressedApplication.getUserProperties()
,
JRootPane.defaultButton
public void addKeyListener(KeyListener kl)
addKeyListener
in class Component
public void saveState()
public String getText()
public void setText(String s)
public void addChangeListener(ChangeListener l)
l
- the ChangeListener to addpublic void addActionListener(ActionListener l)
addActionListener
in class JComboBox
public void requestFocus()
requestFocus
in class JComponent
public void setMaxWidth(int maxWidth)
maxWidth
- give a number in pixels, or -1
to use
defaultpublic void setMinWidth(int minWidth)
minWidth
- give a number in pixels, or -1
to use
defaultpublic Dimension getMaximumSize()
getMaximumSize
in class JComponent
setMaxWidth(int)
public Dimension getMinimumSize()
getMinimumSize
in class JComponent
setMinWidth(int)
public Dimension getPreferredSize()
getPreferredSize
in class JComponent
setMinWidth(int)
,
setMaxWidth(int)
public static String showInputDialog(Component owner, Object message, String key)
owner
- The dialog ownermessage
- The message to displaykey
- The key under which the recent items are stored in the user
propertiesJOptionPane.showInputDialog(Component,Object)
public static String showInputDialog(Component owner, Object message, String title, int messageType, String key)
owner
- The dialog ownermessage
- The message to displaytitle
- The dialog titlemessageType
- The message typekey
- The key under which the recent items are stored in the user
propertiesJOptionPane.showInputDialog(Component,Object,String,int)
public String getKey()
public void setKey(String key)
key
- New value of property key.public int getNumberOfItems()
public void setNumberOfItems(int numberOfItems)
numberOfItems
- New value of property numberOfItems.public boolean isClickDefault()
public void setClickDefault(boolean clickDefault)
clickDefault
- New value of property clickDefault.Copyright © 2000–2017 FreeHEP. All rights reserved.