public class JHistoryTextField extends JComponent
JTextField
with a JComboBox
. Text can be entered
freely into the text field. The class keeps a history of recently entered texts, which
can be selected in the JComboBox
. The history is optionally stored as
Preferences
if a unique name is given to the constructor.JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
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 |
---|
JHistoryTextField()
Creates a new
JHistoryTextField . |
JHistoryTextField(String name)
Creates a new
JHistoryTextField . |
Modifier and Type | Method and Description |
---|---|
void |
addActionListener(ActionListener l)
Adds an
ActionListener . |
protected void |
addHistory(String text)
Adds a text to the top of the history.
|
void |
clearHistory()
Clears the entire history.
|
protected void |
fireActionEvent(ActionEvent e)
Informs all registered ActionListeners about a new ActionEvent.
|
int |
getCurrentSize()
Gets the current number of history entries.
|
List<String> |
getHistory()
Gets a
List of the current history. |
int |
getHistorySize()
Gets the current history size.
|
String |
getText()
Gets the text that is currently shown in this component.
|
boolean |
isAutoSelection()
Checks if the auto selection mode is enabled.
|
protected void |
recallHistory(String name)
Recalls the history from preferences, using the given name.
|
void |
removeActionListener(ActionListener l)
Removes an ActionListener.
|
void |
setAutoSelection(boolean as)
Sets the auto selection mode.
|
void |
setEnabled(boolean enabled) |
void |
setHistorySize(int size)
Sets the maximum history size.
|
void |
setText(String text)
Sets the text to be shown in this component.
|
protected void |
storeHistory(String name)
Stores the current history to the preferences, using the given name.
|
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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
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, getAccessibleContext, 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
public JHistoryTextField()
JHistoryTextField
. The history will only be stored during the
lifetime of this object.public JHistoryTextField(String name)
JHistoryTextField
. The history will be persistently stored
using Preferences
. You must provide a unique name for the history to be
stored. It is strongly recommended to use the Java notation for unique names, as
used in package names (i.e. your domain name in reverse notation, following a
unique string of your choice).name
- Name which is used to persist the history.public void setHistorySize(int size)
size
- New history sizepublic int getHistorySize()
public void setAutoSelection(boolean as)
as
- Auto selection mode.public boolean isAutoSelection()
public void setText(String text)
text
- Text to be set.public String getText()
protected void addHistory(String text)
text
- Text to be added to the history.public List<String> getHistory()
List
of the current history. The list is unmodifiable and sorted
from the most recent to the least recent history entry.List
of all history entriespublic int getCurrentSize()
public void clearHistory()
public void setEnabled(boolean enabled)
setEnabled
in class JComponent
protected void storeHistory(String name) throws BackingStoreException
name
- Name to file the history to.BackingStoreException
- if it was not possible to store the history.protected void recallHistory(String name) throws BackingStoreException
name
- Name the history was filed to.BackingStoreException
- if it was not possible to recall the history.public void addActionListener(ActionListener l)
ActionListener
. It will be invoked if a new text has been entered.
If it was already added, nothing will happen.l
- ActionListener to be added.public void removeActionListener(ActionListener l)
l
- ActionListener to be removed.protected void fireActionEvent(ActionEvent e)
e
- The ActionEvent to be broadcasted.Copyright © 2004–2016. All rights reserved.