public class ComboBoxSearchable extends Searchable implements javax.swing.event.ListDataListener, java.beans.PropertyChangeListener
ComboBoxSearchable
is an concrete implementation of Searchable
that enables the search function
in non-editable JComboBox. It's very simple to use it. Assuming you have a JComboBox, all you need to do is to
call
Now the JComboBox will have the search function.
JComboBox comboBox = ....;
ComboBoxSearchable searchable = new ComboBoxSearchable(comboBox);
JComboBox comboBox = ....;
ComboBoxSearchable searchable = new ComboBoxSearchable(comboBox) {
protected String convertElementToString(Object object) {
...
}
};
Additional customization can be done on the base Searchable class such as background and foreground color,
keystrokes, case sensitivity,Searchable.SearchField, Searchable.SearchPopup
_component, _componentListener, _focusListener, _keyListener, CLIENT_PROPERTY_SEARCHABLE, listenerList, PROPERTY_SEARCH_TEXT
Constructor and Description |
---|
ComboBoxSearchable(javax.swing.JComboBox comboBox) |
Modifier and Type | Method and Description |
---|---|
void |
contentsChanged(javax.swing.event.ListDataEvent e) |
protected java.lang.String |
convertElementToString(java.lang.Object object)
Converts the element in JCombobox to string.
|
protected java.lang.Object |
getElementAt(int index)
Gets the element at the specified index.
|
protected int |
getElementCount()
Gets the total element count in the component.
|
protected int |
getSelectedIndex()
Gets the selected index in the component.
|
void |
intervalAdded(javax.swing.event.ListDataEvent e) |
void |
intervalRemoved(javax.swing.event.ListDataEvent e) |
boolean |
isShowPopupDuringSearching()
Checks if the popup is showing during searching.
|
void |
propertyChange(java.beans.PropertyChangeEvent evt) |
protected void |
setSelectedIndex(int index,
boolean incremental)
Sets the selected index.
|
void |
setShowPopupDuringSearching(boolean showPopupDuringSearching)
Sets the property which determines if the popup should be shown during searching.
|
void |
uninstallListeners()
Uninstall the listeners that installed before.
|
addPropertyChangeListener, addSearchableListener, adjustSelectedIndex, compare, compare, createComponentListener, createFocusListener, createKeyListener, createSearchPopup, findFirst, findFromCursor, findLast, findNext, findPrevious, firePropertyChangeEvent, fireSearchableEvent, getBackground, getComponent, getCurrentIndex, getCursor, getForeground, getMismatchForeground, getPopupLocation, getPopupLocationRelativeTo, getResourceString, getSearchable, getSearchableListeners, getSearchableProvider, getSearchingDelay, getSearchingText, getSearchLabel, getWildcardSupport, hidePopup, installListeners, isActivateKey, isCaseSensitive, isDeactivateKey, isFindFirstKey, isFindLastKey, isFindNextKey, isFindPreviousKey, isFromStart, isHeavyweightComponentEnabled, isIncrementalSelectKey, isNavigationKey, isPopupVisible, isProcessModelChangeEvent, isRepeats, isReverseOrder, isSelectAllKey, isWildcardEnabled, keyTypedOrPressed, removePropertyChangeListener, removeSearchableListener, reverseFindFromCursor, setBackground, setCaseSensitive, setCursor, setCursor, setForeground, setFromStart, setHeavyweightComponentEnabled, setMismatchForeground, setPopupLocation, setPopupLocationRelativeTo, setProcessModelChangeEvent, setRepeats, setReverseOrder, setSearchableProvider, setSearchingDelay, setSearchLabel, setWildcardEnabled, setWildcardSupport, showPopup
public void uninstallListeners()
Searchable
uninstallListeners
in class Searchable
public boolean isShowPopupDuringSearching()
public void setShowPopupDuringSearching(boolean showPopupDuringSearching)
showPopupDuringSearching
- the flag indicating if we should show popup during searchingprotected void setSelectedIndex(int index, boolean incremental)
Searchable
setSelectedIndex
in class Searchable
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.protected int getSelectedIndex()
Searchable
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).
getSelectedIndex
in class Searchable
protected java.lang.Object getElementAt(int index)
Searchable
getElementAt
in class Searchable
index
- the indexprotected int getElementCount()
Searchable
getElementCount
in class Searchable
protected java.lang.String convertElementToString(java.lang.Object object)
toString()
of whatever
element that returned from list.getModel().getElementAt(i)
.convertElementToString
in class Searchable
object
- the object to be convertedpublic void contentsChanged(javax.swing.event.ListDataEvent e)
contentsChanged
in interface javax.swing.event.ListDataListener
public void intervalAdded(javax.swing.event.ListDataEvent e)
intervalAdded
in interface javax.swing.event.ListDataListener
public void intervalRemoved(javax.swing.event.ListDataEvent e)
intervalRemoved
in interface javax.swing.event.ListDataListener
public void propertyChange(java.beans.PropertyChangeEvent evt)
propertyChange
in interface java.beans.PropertyChangeListener