|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.text.JTextComponent
javax.swing.JTextField
org.jdesktop.swingx.JXTextField
org.jdesktop.swingx.JXSearchField
public class JXSearchField
A text field with a find icon in which the user enters text that identifies
items to search for.
JXSearchField almost looks and behaves like a native Windows Vista search
box, a Mac OS X search field, or a search field like the one used in Mozilla
Thunderbird 2.0 - depending on the current look and feel.
JXSearchField is a text field that contains a find button and a cancel
button. The find button normally displays a lens icon appropriate for the
current look and feel. The cancel button is used to clear the text and
therefore only visible when text is present. It normally displays a 'x' like
icon. Text can also be cleared, using the 'Esc' key.
The position of the find and cancel buttons can be customized by either
changing the search fields (text) margin or button margin, or by changing the
JXSearchField.LayoutStyle
.
JXSearchField supports two different search modes: JXSearchField.SearchMode.INSTANT
and JXSearchField.SearchMode.REGULAR
.
A search can be performed by registering an ActionListener
. The
ActionEvent
s command property contains the text to search for. The
search should be cancelled, when the command text is empty or null.
RecentSearches
,
Serialized FormNested Class Summary | |
---|---|
class |
JXSearchField.FindAction
Invoked when the find button is pressed. |
static class |
JXSearchField.LayoutStyle
Defines, how the find and cancel button are layouted. |
static class |
JXSearchField.SearchMode
Defines when action events are posted. |
Nested classes/interfaces inherited from class javax.swing.JTextField |
---|
javax.swing.JTextField.AccessibleJTextField |
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent |
---|
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.DropLocation, javax.swing.text.JTextComponent.KeyBinding |
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 |
---|
Fields inherited from class javax.swing.JTextField |
---|
notifyAction |
Fields inherited from class javax.swing.text.JTextComponent |
---|
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY |
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 javax.swing.SwingConstants |
---|
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
JXSearchField()
Creates a new search field with a default prompt. |
|
JXSearchField(java.lang.String prompt)
Creates a new search field with the given prompt and JXSearchField.SearchMode.INSTANT . |
Method Summary | |
---|---|
protected javax.swing.JButton |
createCancelButton()
Creates and returns the cancel button. |
protected javax.swing.JButton |
createFindButton()
Creates and returns the find button. |
protected javax.swing.JButton |
createPopupButton()
Creates and returns the popup button. |
void |
customSetUIProperty(java.lang.String propertyName,
java.lang.Object value)
Hack to enable the UI delegate to set default values depending on the current Look and Feel, without overriding custom values. |
void |
customSetUIProperty(java.lang.String propertyName,
java.lang.Object value,
boolean override)
Hack to enable the UI delegate to set default values depending on the current Look and Feel, without overriding custom values. |
java.awt.event.ActionListener |
getCancelAction()
Returns the cancel action, or an instance of ClearAction , if
none has been set. |
javax.swing.JButton |
getCancelButton()
Returns the cancel button. |
java.awt.event.ActionListener |
getFindAction()
Returns the action that is invoked when the enter key is pressed or the find button is clicked. |
javax.swing.JButton |
getFindButton()
Returns the find button. |
javax.swing.JPopupMenu |
getFindPopupMenu()
Returns the find popup menu. |
int |
getInstantSearchDelay()
Get the instant search delay in milliseconds. |
javax.swing.Timer |
getInstantSearchTimer()
Returns the Timer used to delay the firing of action events in
instant search mode when the user enters text. |
JXSearchField.LayoutStyle |
getLayoutStyle()
Get the current JXSearchField.LayoutStyle . |
javax.swing.JButton |
getPopupButton()
Returns the popup button. |
RecentSearches |
getRecentSearches()
TODO |
java.lang.String |
getRecentSearchesSaveKey()
Returns the key used to persist recent searches. |
JXSearchField.SearchMode |
getSearchMode()
Returns the current JXSearchField.SearchMode . |
boolean |
hasFocus()
Returns true if this search field is the focus owner or
the find popup menu is visible. |
boolean |
isInstantSearchMode()
Returns true if the current JXSearchField.SearchMode is
JXSearchField.SearchMode.INSTANT . |
boolean |
isMacLayoutStyle()
Returns true if the current JXSearchField.LayoutStyle is
JXSearchField.LayoutStyle.MAC . |
boolean |
isManagingRecentSearches()
TODO |
boolean |
isRegularSearchMode()
Returns true if the current JXSearchField.SearchMode is
JXSearchField.SearchMode.REGULAR . |
boolean |
isUseNativeSearchFieldIfPossible()
|
boolean |
isUseSeperatePopupButton()
Returns true if the popup button should be visible and
used for displaying the find popup menu. |
boolean |
isVistaLayoutStyle()
Returns true if the current JXSearchField.LayoutStyle is
JXSearchField.LayoutStyle.VISTA . |
void |
postActionEvent()
Overriden to prevent any delayed ActionEvent s from being sent
after posting this action. |
void |
setCancelAction(java.awt.event.ActionListener cancelAction)
Sets the action that is invoked, when the user presses the 'Esc' key or clicks the cancel button. |
void |
setEditable(boolean b)
Updates the cancel, find and popup buttons enabled state in addition to setting the search fields editable state. |
void |
setEnabled(boolean enabled)
Updates the cancel, find and popup buttons enabled state in addition to setting the search fields enabled state. |
void |
setFindAction(java.awt.event.ActionListener findAction)
Sets the action that is invoked when the enter key is pressed or the find button is clicked. |
void |
setFindPopupMenu(javax.swing.JPopupMenu findPopupMenu)
Sets the popup menu that will be displayed when the popup button is clicked. |
void |
setInstantSearchDelay(int instantSearchDelay)
Set the instant search delay in milliseconds. |
void |
setLayoutStyle(JXSearchField.LayoutStyle layoutStyle)
Set the current JXSearchField.LayoutStyle . |
void |
setMargin(java.awt.Insets m)
Set the margin space around the search field's text. |
void |
setPromptFontStyle(java.lang.Integer fontStyle)
Hack to enable the UI delegate to set default values depending on the current Look and Feel, without overriding custom values. |
void |
setRecentSearchesSaveKey(java.lang.String recentSearchesSaveKey)
Installs and manages a recent searches popup menu as the find popup menu, if recentSearchesSaveKey is not null. |
void |
setSearchMode(JXSearchField.SearchMode searchMode)
Sets the current search mode. |
void |
setUseNativeSearchFieldIfPossible(boolean useNativeSearchFieldIfPossible)
|
void |
setUseSeperatePopupButton(boolean useSeperatePopupButton)
Set if the popup button should be used for displaying the find popup menu. |
protected void |
updateButtonState()
Enables the cancel action if this search field is editable and enabled, otherwise it will be disabled. |
void |
updateUI()
Overriden to also update the find popup menu if set. |
Methods inherited from class org.jdesktop.swingx.JXTextField |
---|
addBuddy, addGap, getBuddies, getFocusBehavior, getOuterMargin, getPrompt, getPromptBackground, getPromptFontStyle, getPromptForeground, removeAllBuddies, setFocusBehavior, setOuterMargin, setPrompt, setPromptBackround, setPromptForeground |
Methods inherited from class javax.swing.JTextField |
---|
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, getUIClassID, isValidateRoot, paramString, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setDocument, setFont, setHorizontalAlignment, setScrollOffset |
Methods inherited from class javax.swing.text.JTextComponent |
---|
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setFocusAccelerator, setHighlighter, setKeymap, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, viewToModel, write |
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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, 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, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, 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, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public JXSearchField()
public JXSearchField(java.lang.String prompt)
JXSearchField.SearchMode.INSTANT
.
prompt
- Method Detail |
---|
public JXSearchField.SearchMode getSearchMode()
JXSearchField.SearchMode
.
JXSearchField.SearchMode
.public boolean isInstantSearchMode()
true
if the current JXSearchField.SearchMode
is
JXSearchField.SearchMode.INSTANT
.
true
if the current JXSearchField.SearchMode
is
JXSearchField.SearchMode.INSTANT
public boolean isRegularSearchMode()
true
if the current JXSearchField.SearchMode
is
JXSearchField.SearchMode.REGULAR
.
true
if the current JXSearchField.SearchMode
is
JXSearchField.SearchMode.REGULAR
public void setSearchMode(JXSearchField.SearchMode searchMode)
JXSearchField.SearchMode
for a description of
the different search modes.
searchMode
- JXSearchField.SearchMode.INSTANT
or JXSearchField.SearchMode.REGULAR
public int getInstantSearchDelay()
#setInstantSearchDelay(int)}
public void setInstantSearchDelay(int instantSearchDelay)
JXSearchField.SearchMode.INSTANT
, when the user changes the text, an action
event will be fired after the specified instant search delay.
It is recommended to use a instant search delay to avoid the firing of
unnecessary events. For example when the user replaces the whole text
with a different text the search fields underlying Document
typically fires 2 document events. The first one, because the old text is
removed and the second one because the new text is inserted. If the
instant search delay is 0, this would result in 2 action events being
fired. When a instant search delay is used, the first document event
typically is ignored, because the second one is fired before the delay is
over, which results in a correct behavior because only the last and only
relevant event will be delivered.
instantSearchDelay
- public JXSearchField.LayoutStyle getLayoutStyle()
JXSearchField.LayoutStyle
.
public boolean isVistaLayoutStyle()
true
if the current JXSearchField.LayoutStyle
is
JXSearchField.LayoutStyle.VISTA
.
public boolean isMacLayoutStyle()
true
if the current JXSearchField.LayoutStyle
is
JXSearchField.LayoutStyle.MAC
.
public void setLayoutStyle(JXSearchField.LayoutStyle layoutStyle)
JXSearchField.LayoutStyle
. See JXSearchField.LayoutStyle
for a
description of how this affects layout and behavior of the search field.
layoutStyle
- JXSearchField.LayoutStyle.MAC
or JXSearchField.LayoutStyle.VISTA
public void setMargin(java.awt.Insets m)
setMargin
in class javax.swing.text.JTextComponent
JTextComponent.setMargin(java.awt.Insets)
public final java.awt.event.ActionListener getCancelAction()
ClearAction
, if
none has been set.
public final void setCancelAction(java.awt.event.ActionListener cancelAction)
cancelAction
- public final javax.swing.JButton getCancelButton()
createCancelButton()
to create the cancel button and
registers an ActionListener
that delegates actions to the
ActionListener
returned by getCancelAction()
, if
needed.
protected javax.swing.JButton createCancelButton()
getCancelButton()
public final java.awt.event.ActionListener getFindAction()
JXSearchField.FindAction
will be returned.
public final void setFindAction(java.awt.event.ActionListener findAction)
public final javax.swing.JButton getFindButton()
createFindButton()
to create the find button and registers
an ActionListener
that delegates actions to the
ActionListener
returned by getFindAction()
, if needed.
protected javax.swing.JButton createFindButton()
#getSearchAction()
.
Override to use a custom find button.
getFindButton()
public final javax.swing.JButton getPopupButton()
isUseSeperatePopupButton()
returns true
. Otherwise the popup menu will be displayed
when the find button is clicked.
protected javax.swing.JButton createPopupButton()
getPopupButton()
public boolean isUseSeperatePopupButton()
true
if the popup button should be visible and
used for displaying the find popup menu. Otherwise, the find popup menu
will be displayed when the find button is clicked.
true
if the popup button should be usedpublic void setUseSeperatePopupButton(boolean useSeperatePopupButton)
useSeperatePopupButton
- public boolean isUseNativeSearchFieldIfPossible()
public void setUseNativeSearchFieldIfPossible(boolean useNativeSearchFieldIfPossible)
public void setEditable(boolean b)
setEditable
in class javax.swing.text.JTextComponent
updateButtonState()
,
JTextComponent.setEditable(boolean)
public void setEnabled(boolean enabled)
setEnabled
in class javax.swing.JComponent
updateButtonState()
,
JComponent.setEnabled(boolean)
protected void updateButtonState()
public void setFindPopupMenu(javax.swing.JPopupMenu findPopupMenu)
isUseSeperatePopupButton()
returns false
, the
popup button will be displayed instead of the find button. Otherwise the
popup button will be displayed in addition to the find button.
The find popup menu is managed using NativeSearchFieldSupport
to
achieve compatibility with the native search field support provided by
the Mac Look And Feel since Mac OS 10.5.
If a recent searches save key has been set and therefore a recent
searches popup menu is installed, this method does nothing. You must
first remove the recent searches save key, by calling
setRecentSearchesSaveKey(String)
with a null
parameter.
findPopupMenu
- the popup menu, which will be displayed when the popup button
is clickedsetRecentSearchesSaveKey(String)
,
RecentSearches
public javax.swing.JPopupMenu getFindPopupMenu()
setFindPopupMenu(JPopupMenu)
public final boolean isManagingRecentSearches()
public java.lang.String getRecentSearchesSaveKey()
setRecentSearchesSaveKey(String)
public void setRecentSearchesSaveKey(java.lang.String recentSearchesSaveKey)
recentSearchesSaveKey
is not null. Otherwise, removes
the popup menu and stops managing recent searches.
recentSearchesSaveKey
- this key is used to persist the recent searches.setFindAction(ActionListener)
,
isManagingRecentSearches()
,
RecentSearches
public RecentSearches getRecentSearches()
public javax.swing.Timer getInstantSearchTimer()
Timer
used to delay the firing of action events in
instant search mode when the user enters text.
This timer calls postActionEvent()
.
Timer
used to delay the firing of action eventspublic boolean hasFocus()
true
if this search field is the focus owner or
the find popup menu is visible.
This is a hack to make the search field paint the focus indicator in Mac
OS X Aqua when the find popup menu is visible.
hasFocus
in class java.awt.Component
true
if this search field is the focus owner or
the find popup menu is visiblepublic void updateUI()
updateUI
in class javax.swing.text.JTextComponent
public void setPromptFontStyle(java.lang.Integer fontStyle)
setPromptFontStyle
in class JXTextField
PromptSupport.setFontStyle(Integer, javax.swing.text.JTextComponent)
public void customSetUIProperty(java.lang.String propertyName, java.lang.Object value)
propertyName
- the name of the property to changevalue
- the new value of the propertypublic void customSetUIProperty(java.lang.String propertyName, java.lang.Object value, boolean override)
propertyName
- the name of the property to changevalue
- the new value of the propertyoverride
- override custom valuespublic void postActionEvent()
ActionEvent
s from being sent
after posting this action.
For example, if the current JXSearchField.SearchMode
is
JXSearchField.SearchMode.INSTANT
and the instant search delay is greater 0. The
user enters some text and presses enter. This method will be invoked
immediately because the users presses enter. However, this method would
be invoked after the instant search delay, if we would not prevent it
here.
postActionEvent
in class javax.swing.JTextField
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |