Package com.jidesoft.swing
Class Searchable
java.lang.Object
com.jidesoft.swing.Searchable
- Direct Known Subclasses:
ComboBoxSearchable
,ListSearchable
,TableSearchable
,TextComponentSearchable
,TreeSearchable
JList, JTable and JTree are three data-rich components. They can be used to display a huge amount of data so
searching function will be very a useful feature in those components.
Select all feature - If you type in a searching text and press CTRL+A, all the occurrences of that searching string will be selected. This is a very handy feature. For example you want to delete all rows in a table whose name column begins with "old". So you can type in "old" and press CTRL+A, now all rows beginning with "old" will be selected. Pressing delete will delete all of them.
Basic regular expression support - It allows '?' to match any letter or digit, or '*' to match several letters or digits. Even though it's possible to implement full regular expression support, we don't want to do that. The reason is the regular expression is very complex, it's probably not a good idea to let user type in such a complex expression in a small popup window. However if your user is very familiar with regular expression, you can add the feature to
Searchable
is such a class that
can make JList, JTable and JTree searchable. User can simply type in any string they want to search for and use arrow
keys to navigate to next or previous occurrence.
Searchable
is a base abstract class. ListSearchable
, TableSearchable
and
TreeSearchable
are implementations to make JList, JTable and JTree searchable respectively. For each
implementation, there are five methods need to be implemented. protected abstract int getSelectedIndex()
protected abstract void setSelectedIndex(int index, boolean incremental)
protected abstract int getElementCount()
protected abstract Object getElementAt(int index)
protected abstract String convertElementToString(Object element)
isActivateKey(java.awt.event.KeyEvent)
, isDeactivateKey(java.awt.event.KeyEvent)
, isFindFirstKey(java.awt.event.KeyEvent)
,isFindLastKey(java.awt.event.KeyEvent)
, isFindNextKey(java.awt.event.KeyEvent)
, isFindPreviousKey(java.awt.event.KeyEvent)
to provide its own set
of keys.
In addition to press up/down arrow to find next occurrence or previous occurrence of particular string, there are
several other features that are very handy.
Multiple selection feature - If you press CTRL key and hold it while pressing up and down arrow, it will find
next/previous occurrence while keeping existing selections. Select all feature - If you type in a searching text and press CTRL+A, all the occurrences of that searching string will be selected. This is a very handy feature. For example you want to delete all rows in a table whose name column begins with "old". So you can type in "old" and press CTRL+A, now all rows beginning with "old" will be selected. Pressing delete will delete all of them.
Basic regular expression support - It allows '?' to match any letter or digit, or '*' to match several letters or digits. Even though it's possible to implement full regular expression support, we don't want to do that. The reason is the regular expression is very complex, it's probably not a good idea to let user type in such a complex expression in a small popup window. However if your user is very familiar with regular expression, you can add the feature to
Searchable
. All you need to do is to override compare(String, String)
method and implement by
yourself.
As this is an abstract class, please refer to to javadoc of ListSearchable
,TreeSearchable
, and TableSearchable
to find out how to use it with JList, JTree and JTable respectively.
This component has a timer. If user types very fast, it will accumulate them together and generate only one searching
action. The timer can be controlled by setSearchingDelay(int)
.
By default we will use lightweight popup for the sake of performance. But if you use heavyweight component which
could obscure the lightweight popup, you can call setHeavyweightComponentEnabled(boolean)
to true so that
heavyweight popup will be used.
When a Searchable
is installed on a component, component.getClientProperty(Searchable.CLIENT_PROPERTY_SEARCHABLE)
will give you the Searchable instance. You can use static method getSearchable(javax.swing.JComponent)
to
get it too.
Last but not the least, only one Searchable is allowed on a component. If you install another one, it will remove the
first one and then install the new one.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
The popup panel for search label and search text field.protected class
A text field for searching text.class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final JComponent
protected ComponentListener
protected FocusListener
protected KeyListener
protected int
static final String
The client property for Searchable instance.protected EventListenerList
A list of event listeners for this component.static final String
-
Constructor Summary
ConstructorsConstructorDescriptionSearchable
(JComponent component) Creates a Searchable.Searchable
(JComponent component, SearchableProvider searchableProvider) Creates a Searchable. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPropertyChangeListener
(PropertyChangeListener propertychangelistener) Adds the property change listener.void
Adds the specified listener to receive searchable events from this searchable.void
adjustSelectedIndex
(int index, boolean incremental) Sets the selected index.protected void
Cancel highlight all.protected boolean
Checks if the element matches the searching text.protected boolean
Checks if the element string matches the searching text.protected abstract String
convertElementToString
(Object element) Converts the element that returns from getElementAt() to string.convertToString
(Object element) Converts the element to String.protected ComponentListener
Creates a component listener that updates the popup when component is hidden, moved or resized.protected FocusListener
Creates a FocusListener.protected KeyListener
Creates the KeyListener and listen to key typed in the component.protected Searchable.SearchPopup
createSearchPopup
(String searchingText) Creates the popup to hold the searching text.findAll
uses the Searchable to find all the element indices that match the searching string.int
Finds the first element that matches the searching text.int
Finds the first element that matches the searching text exactly.int
Finds the next matching index from the cursor.int
Finds the last element that matches the searching text.int
Finds the next matching index from the cursor.int
Finds the previous matching index from the cursor.void
firePropertyChangeEvent
(String searchingText) protected void
Fires a searchable event.Gets the background color used inn the search popup.Gets the actual component which installed this Searchable.protected int
int
Gets the cursor which is the index of current location when searching.protected abstract Object
getElementAt
(int index) Gets the element at the specified index.getElementAtAsString
(int index) Gets the element at the specified index as string usingconvertElementToString(Object)
method.protected abstract int
Gets the total element count in the component.Gets the foreground color used inn the search popup.Gets the foreground color when the searching text doesn't match with any of the elements in the component.int
Gets the popup location.Gets the component that the location of the popup relative to.int
Gets the timeout for showing the popup.protected String
getResourceString
(String key) Gets the localized string from resource bundle.static Searchable
getSearchable
(JComponent component) Gets the Searchable installed on the component.Returns an array of all theSearchableListener
s added to thisSearchableGroup
withaddSearchableListener
.int
If it returns a positive number, it will wait for that many ms before doing the search.Gets the searching text.Gets the current text that appears in the search popup.protected abstract int
Gets the selected index in the component.Gets the WildcardSupport.void
Hides the popup.protected void
Highlight all matching cases in the target.void
Installs necessary listeners to the component.protected boolean
Checks if the key in KeyEvent should activate the search popup.boolean
Checks if the case is sensitive during searching.boolean
Gets the flag indicating if the Searchable should count all matches for every search.protected boolean
Checks if the key in KeyEvent should hide the search popup.protected boolean
Checks if the key is used as a key to find the first occurrence.protected boolean
Checks if the key is used as a key to find the last occurrence.protected boolean
Checks if the key is used as a key to find the next occurrence.protected boolean
Checks if the key is used as a key to find the previous occurrence.boolean
This is a property of how to compare searching text with the data.boolean
boolean
Get the flag indicating if the search popup should be hidden on the component's event.protected boolean
Checks if the key will trigger incremental selection.protected boolean
Checks if the key is used as a navigation key.boolean
Check if the searchable popup is visible.boolean
Get the flag if we should process model change event.boolean
Checks if restart from the beginning when searching reaches the end or restart from the end when reaches beginning.boolean
Checks the searching order.boolean
Returns if a given listener is already installed.protected boolean
Checks if the key will trigger selecting all.boolean
Checks if it supports wildcard in searching text.protected void
This method is called when a key is typed or pressed.void
removePropertyChangeListener
(PropertyChangeListener propertychangelistener) Removes the property change listener.void
Removes the specified searchable listener so that it no longer receives searchable events.int
Finds the previous matching index from the cursor.protected void
Actions to take on searching text empty scenarioprotected void
Select the index for the searching text.void
setBackground
(Color background) Sets the background color used by popup.void
setCaseSensitive
(boolean caseSensitive) Sets the case sensitive flag.void
setCountMatch
(boolean countMatch) Sets the flag indicating if the Searchable should count all matches for every search.void
setCursor
(int cursor) Sets the cursor which is the index of current location when searching.void
setCursor
(int cursor, boolean incremental) Sets the cursor which is the index of current location when searching.void
setForeground
(Color foreground) Sets the foreground color used by popup.void
setFromStart
(boolean fromStart) Sets the fromStart property.void
setHeavyweightComponentEnabled
(boolean heavyweightComponentEnabled) void
setHideSearchPopupOnEvent
(boolean hideSearchPopupOnEvent) Set the flag indicating if the search popup should be hidden on the component's event.void
setMismatchForeground
(Color mismatchForeground) Sets the foreground for mismatch.void
setPopupLocation
(int popupLocation) Sets the popup location.void
setPopupLocationRelativeTo
(Component popupLocationRelativeTo) Sets the location of the popup relative to the specified component.void
setPopupTimeout
(int popupTimeout) Sets the timeout for showing the popup.void
setProcessModelChangeEvent
(boolean processModelChangeEvent) Set the flag if we should process model change event.void
setRepeats
(boolean repeats) Sets the repeat flag.void
setReverseOrder
(boolean reverseOrder) Sets the searching order.void
setSearchableProvider
(SearchableProvider searchableProvider) void
setSearchingDelay
(int searchingDelay) If this flag is set to a positive number, it will wait for that many ms before doing the search.void
setSearchLabel
(String searchLabel) Sets the text that appears in the search popup.protected abstract void
setSelectedIndex
(int index, boolean incremental) Sets the selected index.void
setWildcardEnabled
(boolean wildcardEnabled) Enable or disable the usage of wildcard.void
setWildcardSupport
(WildcardSupport wildcardSupport) Sets the WildcardSupport.void
Shows the search popup.protected void
textChanged
(String text) void
Uninstall the listeners that installed before.
-
Field Details
-
_component
-
_matchCount
protected int _matchCount -
_componentListener
-
_keyListener
-
_focusListener
-
PROPERTY_SEARCH_TEXT
- See Also:
-
listenerList
A list of event listeners for this component. -
CLIENT_PROPERTY_SEARCHABLE
The client property for Searchable instance. When Searchable is installed on a component, this client property has the Searchable.- See Also:
-
-
Constructor Details
-
Searchable
Creates a Searchable.- Parameters:
component
- component where the Searchable will be installed.
-
Searchable
Creates a Searchable.- Parameters:
component
- component where the Searchable will be installed.searchableProvider
- the Searchable Provider.
-
-
Method Details
-
getSelectedIndex
protected abstract int getSelectedIndex()Gets the selected index in the component. The concrete implementation should call methods on the component to retrieve the current selected index. If the component supports multiple selection, it's OK just return the index of the first selection.Here are some examples. In the case of JList, the index is the row index. In the case of JTree, the index is the row index too. In the case of JTable, depending on the selection mode, the index could be row index (in row selection mode), could be column index (in column selection mode) or could the cell index (in cell selection mode).
- Returns:
- the selected index.
-
setSelectedIndex
protected abstract void setSelectedIndex(int index, boolean incremental) Sets the selected index. The concrete implementation should call methods on the component to select the element at the specified index. The incremental flag is used to do multiple select. If the flag is true, the element at the index should be added to current selection. If false, you should clear previous selection and then select the element.- Parameters:
index
- the index to be selectedincremental
- a flag to enable multiple selection. If the flag is true, the element at the index should be added to current selection. If false, you should clear previous selection and then select the element.
-
adjustSelectedIndex
public void adjustSelectedIndex(int index, boolean incremental) Sets the selected index. The reason we have this method is just for back compatibility. All the method do is just to invokesetSelectedIndex(int, boolean)
. Please do NOT try to override this method. Always overridesetSelectedIndex(int, boolean)
instead.- Parameters:
index
- the index to be selectedincremental
- a flag to enable multiple selection. If the flag is true, the element at the index should be added to current selection. If false, you should clear previous selection and then select the element.
-
getElementCount
protected abstract int getElementCount()Gets the total element count in the component. Different concrete implementation could have different interpretation of the count. This is totally OK as long as it's consistent in all the methods. For example, the index parameter in other methods should be always a valid value within the total count.- Returns:
- the total element count.
-
getElementAt
Gets the element at the specified index. The element could be any data structure that internally used in the component. The convertElementToString method will give you a chance to convert the element to string which is used to compare with the string that user types in.- Parameters:
index
- the index- Returns:
- the element at the specified index.
-
convertElementToString
Converts the element that returns from getElementAt() to string.- Parameters:
element
- the element to be converted- Returns:
- the string representing the element in the component.
-
convertToString
Converts the element to String. This method will invokeconvertElementToString(Object)
only. This method is added to provide a public method for ShrinkSearchSupport without breaking the existing code of the customers.- Parameters:
element
- the element to be converted- Returns:
- the string representing the element in the component.
- Since:
- 3.4.5
-
isHideSearchPopupOnEvent
public boolean isHideSearchPopupOnEvent()Get the flag indicating if the search popup should be hidden on the component's event. By default, the value is true so that the search popup will be hidden anyway when the component get related events. However, you could set this flag to false if you don't want to hide the search popup in some scenarios. For example, JIDE ComboBoxShrinkSearchableSupport will set this flag to false temporarily when it tries to shrink the list.- Returns:
- true if the search popup is hidden on event. Otherwise false.
-
setHideSearchPopupOnEvent
public void setHideSearchPopupOnEvent(boolean hideSearchPopupOnEvent) Set the flag indicating if the search popup should be hidden on the component's event.- Parameters:
hideSearchPopupOnEvent
- the flag- See Also:
-
hidePopup
public void hidePopup()Hides the popup. -
getSearchableProvider
-
setSearchableProvider
-
installListeners
public void installListeners()Installs necessary listeners to the component. This method will be called automatically when Searchable is created. -
createComponentListener
Creates a component listener that updates the popup when component is hidden, moved or resized.- Returns:
- a ComponentListener.
-
createKeyListener
Creates the KeyListener and listen to key typed in the component.- Returns:
- the KeyListener.
-
createFocusListener
Creates a FocusListener. We use it to hide the popup when the component loses focus.- Returns:
- a FocusListener.
-
uninstallListeners
public void uninstallListeners()Uninstall the listeners that installed before. This method is never called because we don't have the control of the life cycle of the component. However you can call this method if you don't want the component to be searchable any more. -
addPropertyChangeListener
Adds the property change listener. The only property change event that will be fired is the "searchText" property which will be fired when user types in a different search text in the popup.- Parameters:
propertychangelistener
- the listener
-
removePropertyChangeListener
Removes the property change listener.- Parameters:
propertychangelistener
- the listener
-
firePropertyChangeEvent
-
searchingTextEmpty
protected void searchingTextEmpty()Actions to take on searching text empty scenario -
compare
Checks if the element matches the searching text.- Parameters:
element
- the element to be checkedsearchingText
- the searching text- Returns:
- true if matches.
-
compare
Checks if the element string matches the searching text. Different fromcompare(Object, String)
, this method is after the element has been converted to string usingconvertElementToString(Object)
.- Parameters:
text
- the text to be checkedsearchingText
- the searching text- Returns:
- true if matches.
-
getCursor
public int getCursor()Gets the cursor which is the index of current location when searching. The value will be used in findNext and findPrevious.- Returns:
- the current position of the cursor.
-
setCursor
public void setCursor(int cursor) Sets the cursor which is the index of current location when searching. The value will be used in findNext and findPrevious.- Parameters:
cursor
- the new position of the cursor.
-
setCursor
public void setCursor(int cursor, boolean incremental) Sets the cursor which is the index of current location when searching. The value will be used in findNext and findPrevious. We will call this method automatically inside this class. However, if you ever callsetSelectedIndex(int, boolean)
method from your code, you should call this method with the same parameters.- Parameters:
cursor
- the new position of the cursor.incremental
- a flag to enable multiple selection. If the flag is true, the element at the index should be added to current selection. If false, you should clear previous selection and then select the element.
-
highlightAll
protected void highlightAll()Highlight all matching cases in the target. In default implementation, it will just search all texts in the target to highlight all. If you have a really huge text to search, you may want to override this method to have a lazy behavior on visible areas only. -
cancelHighlightAll
protected void cancelHighlightAll()Cancel highlight all. By default, it does nothing. However, if you want to overridehighlightAll()
, you may want to override this method to notify your Searchable that the highlightAll button is to be released. -
select
Select the index for the searching text.- Parameters:
index
- the start offsetsearchingText
- the searching text presented in the searchable event to be fired here.
-
findNext
Finds the next matching index from the cursor.- Parameters:
s
- the searching text- Returns:
- the next index that the element matches the searching text.
-
getCurrentIndex
protected int getCurrentIndex() -
findPrevious
Finds the previous matching index from the cursor.- Parameters:
s
- the searching text- Returns:
- the previous index that the element matches the searching text.
-
findFromCursor
Finds the next matching index from the cursor. If it reaches the end, it will restart from the beginning. However is the reverseOrder flag is true, it will finds the previous matching index from the cursor. If it reaches the beginning, it will restart from the end.- Parameters:
s
- the searching text- Returns:
- the next index that the element matches the searching text.
-
reverseFindFromCursor
Finds the previous matching index from the cursor. If it reaches the beginning, it will restart from the end.- Parameters:
s
- the searching text- Returns:
- the next index that the element matches the searching text.
-
findFirst
Finds the first element that matches the searching text.- Parameters:
s
- the searching text- Returns:
- the first element that matches with the searching text.
-
findLast
Finds the last element that matches the searching text.- Parameters:
s
- the searching text- Returns:
- the last element that matches the searching text.
-
keyTypedOrPressed
This method is called when a key is typed or pressed.- Parameters:
e
- the KeyEvent.
-
showPopup
Shows the search popup. By default, the search popup will be visible automatically when user types in the first key (in the case of JList, JTree, JTable) or types in designated keystroke (in the case of JTextComponent). So this method is only used when you want to show the popup manually.- Parameters:
searchingText
- the searching text
-
createSearchPopup
Creates the popup to hold the searching text.- Parameters:
searchingText
- the searching text- Returns:
- the searching popup.
-
getSearchingText
Gets the searching text.- Returns:
- the searching text.
-
isFindFirstKey
Checks if the key is used as a key to find the first occurrence.- Parameters:
e
- the key event- Returns:
- true if the key in KeyEvent is a key to find the firstoccurrencee. By default, home key is used.
-
isFindLastKey
Checks if the key is used as a key to find the last occurrence.- Parameters:
e
- the key event- Returns:
- true if the key in KeyEvent is a key to find the last occurrence. By default, end key is used.
-
isFindPreviousKey
Checks if the key is used as a key to find the previous occurrence.- Parameters:
e
- the key event- Returns:
- true if the key in KeyEvent is a key to find the previous occurrence. By default, up arrow key is used.
-
isFindNextKey
Checks if the key is used as a key to find the next occurrence.- Parameters:
e
- the key event- Returns:
- true if the key in KeyEvent is a key to find the next occurrence. By default, down arrow key is used.
-
isActivateKey
Checks if the key in KeyEvent should activate the search popup.- Parameters:
e
- the key event- Returns:
- true if the keyChar is visible except space and tab.
-
isDeactivateKey
Checks if the key in KeyEvent should hide the search popup. If this method return true and the key is not used for navigation purpose (isNavigationKey(java.awt.event.KeyEvent)
return false), the popup will be hidden.- Parameters:
e
- the key event- Returns:
- true if the keyCode in the KeyEvent is escape key, enter key, or any of the arrow keys such as page up, page down, home, end, left, right, up and down.
-
isSelectAllKey
Checks if the key will trigger selecting all.- Parameters:
e
- the key event- Returns:
- true if the key in KeyEvent is a key to trigger selecting all.
-
isIncrementalSelectKey
Checks if the key will trigger incremental selection.- Parameters:
e
- the key event- Returns:
- true if the key in KeyEvent is a key to trigger incremental selection. By default, ctrl down key is used.
-
getMismatchForeground
Gets the foreground color when the searching text doesn't match with any of the elements in the component.- Returns:
- the foreground color for mismatch. If you never call
setMismatchForeground(java.awt.Color)
. red color will be used.
-
setMismatchForeground
Sets the foreground for mismatch.- Parameters:
mismatchForeground
- mismatch forground
-
isCaseSensitive
public boolean isCaseSensitive()Checks if the case is sensitive during searching.- Returns:
- true if the searching is case sensitive.
-
setCaseSensitive
public void setCaseSensitive(boolean caseSensitive) Sets the case sensitive flag. By default, it's false meaning it's a case insensitive search.- Parameters:
caseSensitive
- the flag if searching is case sensitive
-
getSearchingDelay
public int getSearchingDelay()If it returns a positive number, it will wait for that many ms before doing the search. When the searching is complex, this flag will be useful to make the searching efficient. In the other words, if user types in several keys very quickly, there will be only one search. If it returns 0 or negative number, each key will generate a search.- Returns:
- the number of ms delay before searching starts.
-
setSearchingDelay
public void setSearchingDelay(int searchingDelay) If this flag is set to a positive number, it will wait for that many ms before doing the search. When the searching is complex, this flag will be useful to make the searching efficient. In the other words, if user types in several keys very quickly, there will be only one search. If this flag is set to 0 , each key will generate a search with no delay. If this flag is set to a negative number, there are different behaviors. SearchableBar will not generate any search while typing, but others will generate a search with no delay as well as it is set to 0.- Parameters:
searchingDelay
- the number of ms delay before searching start.
-
isRepeats
public boolean isRepeats()Checks if restart from the beginning when searching reaches the end or restart from the end when reaches beginning. Default is false.- Returns:
- true or false.
-
setRepeats
public void setRepeats(boolean repeats) Sets the repeat flag. By default, it's false meaning it will stop searching when reaching the end or reaching the beginning.- Parameters:
repeats
- the repeat flag
-
getForeground
Gets the foreground color used inn the search popup.- Returns:
- the foreground. By default it will use the foreground of tooltip.
-
setForeground
Sets the foreground color used by popup.- Parameters:
foreground
- the foreground
-
getBackground
Gets the background color used inn the search popup.- Returns:
- the background. By default it will use the background of tooltip.
-
setBackground
Sets the background color used by popup.- Parameters:
background
- the background
-
isWildcardEnabled
public boolean isWildcardEnabled()Checks if it supports wildcard in searching text. By default it is true which means user can type in "*" or "?" to match with any characters or any character. If it's false, it will treat "*" or "?" as a regular character.- Returns:
- true if it supports wildcard.
-
setWildcardEnabled
public void setWildcardEnabled(boolean wildcardEnabled) Enable or disable the usage of wildcard.- Parameters:
wildcardEnabled
- the flag if wildcard is enabled- See Also:
-
getWildcardSupport
Gets the WildcardSupport. If user never sets it,DefaultWildcardSupport
will be used.- Returns:
- the WildcardSupport.
-
setWildcardSupport
Sets the WildcardSupport. This class allows you to define what wildcards to use and how to convert the wildcard strings to a regular expression string which is eventually used to search.- Parameters:
wildcardSupport
- the new WildCardSupport.
-
getSearchLabel
Gets the current text that appears in the search popup. By default it is "Search for: ".- Returns:
- the text that appears in the search popup.
-
setSearchLabel
Sets the text that appears in the search popup.- Parameters:
searchLabel
- the search label
-
addSearchableListener
Adds the specified listener to receive searchable events from this searchable.- Parameters:
l
- the searchable listener
-
removeSearchableListener
Removes the specified searchable listener so that it no longer receives searchable events.- Parameters:
l
- the searchable listener
-
getSearchableListeners
Returns an array of all theSearchableListener
s added to thisSearchableGroup
withaddSearchableListener
.- Returns:
- all of the
SearchableListener
s added or an empty array if no listeners have been added - See Also:
-
isSearchableListenerInstalled
Returns if a given listener is already installed.- Parameters:
l
- the listener- Returns:
- true if the listener is already installed. Otherwise false.
- Since:
- 3.2.3
-
fireSearchableEvent
Fires a searchable event.- Parameters:
e
- the event
-
getComponent
Gets the actual component which installed this Searchable.- Returns:
- the actual component which installed this Searchable.
-
getPopupLocation
public int getPopupLocation()Gets the popup location. It could be eitherSwingConstants.TOP
orSwingConstants.BOTTOM
.- Returns:
- the popup location.
-
setPopupLocation
public void setPopupLocation(int popupLocation) Sets the popup location.- Parameters:
popupLocation
- the popup location. The valid values are eitherSwingConstants.TOP
orSwingConstants.BOTTOM
.
-
isReverseOrder
public boolean isReverseOrder()Checks the searching order. By default the searchable starts searching from top to bottom. If this flag is true, it searches from bottom to top.- Returns:
- the reverseOrder flag.
-
setReverseOrder
public void setReverseOrder(boolean reverseOrder) Sets the searching order. By default the searchable starts searching from top to bottom. If this flag is true, it searches from bottom to top.- Parameters:
reverseOrder
- the flag if searching from top to bottom or from bottom to top
-
getResourceString
Gets the localized string from resource bundle. Subclass can override it to provide its own string. Available keys are defined in swing.properties that begin with "Searchable.".- Parameters:
key
- the resource string key- Returns:
- the localized string.
-
isPopupVisible
public boolean isPopupVisible()Check if the searchable popup is visible.- Returns:
- true if visible. Otherwise, false.
-
isHeavyweightComponentEnabled
public boolean isHeavyweightComponentEnabled() -
setHeavyweightComponentEnabled
public void setHeavyweightComponentEnabled(boolean heavyweightComponentEnabled) -
getPopupLocationRelativeTo
Gets the component that the location of the popup relative to.- Returns:
- the component that the location of the popup relative to.
-
setPopupLocationRelativeTo
Sets the location of the popup relative to the specified component. Then based on the value ofgetPopupLocation()
. If you never set, we will use the searchable component or its scroll pane (if exists) as the popupLocationRelativeTo component.- Parameters:
popupLocationRelativeTo
- the relative component
-
isFromStart
public boolean isFromStart()This is a property of how to compare searching text with the data. If it is true, it will useString.startsWith(String)
to do the comparison. Otherwise, it will useString.indexOf(String)
to do the comparison.- Returns:
- true or false.
-
setFromStart
public void setFromStart(boolean fromStart) Sets the fromStart property.- Parameters:
fromStart
- true if the comparison matches from the start of the text only. Otherwise false. The difference is if true, it will use String'sstartWith
method to match. If false, it will useindedxOf
method.
-
getSearchable
Gets the Searchable installed on the component. Null is no Searchable was installed.- Parameters:
component
- the component- Returns:
- the Searchable installed. Null is no Searchable was installed.
-
isProcessModelChangeEvent
public boolean isProcessModelChangeEvent()Get the flag if we should process model change event. By default, the value is true, which means the model change event should be processed. InListShrinkSearchableSupport
case, since we will fire this event while applying filters. This flag will be switched to false before we fire the event and set it back to true. In normal case, please do not set this flag.- Returns:
- true if we should process model change event. Otherwise false.
-
setProcessModelChangeEvent
public void setProcessModelChangeEvent(boolean processModelChangeEvent) Set the flag if we should process model change event. In normal case, please do not set this flag.- Parameters:
processModelChangeEvent
- the flag- See Also:
-
getPopupTimeout
public int getPopupTimeout()Gets the timeout for showing the popup.- Returns:
- the popup timeout.
- See Also:
-
setPopupTimeout
public void setPopupTimeout(int popupTimeout) Sets the timeout for showing the popup. By default, the timeout value is 0, which means no timeout. You could set it to a positive value to automatically hide the search popup after an idle time.- Parameters:
popupTimeout
- the timeout in milliseconds
-
isCountMatch
public boolean isCountMatch()Gets the flag indicating if the Searchable should count all matches for every search.- Returns:
- true if should count all matches. Otherwise false.
- Since:
- 3.5.2
- See Also:
-
setCountMatch
public void setCountMatch(boolean countMatch) Sets the flag indicating if the Searchable should count all matches for every search. By default, the flag is false to keep performance high.- Parameters:
countMatch
- the flag- Since:
- 3.5.2
-
findAll
findAll
uses the Searchable to find all the element indices that match the searching string.- Parameters:
s
- the searching string.- Returns:
- the list of indices.
-
getElementAtAsString
Gets the element at the specified index as string usingconvertElementToString(Object)
method.- Parameters:
index
- the index.- Returns:
- the element at the index converted to string.
-
textChanged
-
findFirstExactly
Finds the first element that matches the searching text exactly.- Parameters:
s
- the searching text- Returns:
- the first element that matches with the searching text.
- Since:
- 3.6.1
-