public class BasicComboPopup extends JPopupMenu implements ComboPopup
This is a basic implementation of the ComboPopup
interface. This class represents the ui for the popup portion of the combo box.
All event handling is handled by listener classes created with the createxxxListener()
methods and internal classes. You can change the behavior of this class by overriding the createxxxListener()
methods and supplying your own event listeners or subclassing from the ones supplied in this class.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans™ has been added to the java.beans
package. Please see XMLEncoder
.
Modifier and Type | Class and Description |
---|---|
class |
BasicComboPopup.InvocationKeyHandler As of Java 2 platform v 1.4, this class is now obsolete and is only included for backwards API compatibility. |
protected class |
BasicComboPopup.InvocationMouseHandler A listener to be registered upon the combo box (not its popup menu) to handle mouse events that affect the state of the popup menu. |
protected class |
BasicComboPopup.InvocationMouseMotionHandler This listener watches for dragging and updates the current selection in the list if it is dragging over the list. |
protected class |
BasicComboPopup.ItemHandler This listener watches for changes to the selection in the combo box. |
class |
BasicComboPopup.ListDataHandler As of 1.4, this class is now obsolete, doesn't do anything, and is only included for backwards API compatibility. |
protected class |
BasicComboPopup.ListMouseHandler This listener hides the popup when the mouse is released in the list. |
protected class |
BasicComboPopup.ListMouseMotionHandler This listener changes the selected item as you move the mouse over the list. |
protected class |
BasicComboPopup.ListSelectionHandler As of Java 2 platform v 1.4, this class is now obsolete, doesn't do anything, and is only included for backwards API compatibility. |
protected class |
BasicComboPopup.PropertyChangeHandler This listener watches for bound properties that have changed in the combo box. |
JPopupMenu.AccessibleJPopupMenu, JPopupMenu.Separator
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
protected JComboBox comboBox
protected JList list
This protected field is implementation specific. Do not access directly or override. Use the accessor methods instead.
getList()
, createList()
protected JScrollPane scroller
This protected field is implementation specific. Do not access directly or override. Use the create method instead
createScroller()
protected boolean valueIsAdjusting
As of Java 2 platform v1.4 this previously undocumented field is no longer used.
protected MouseMotionListener mouseMotionListener
This protected field is implementation specific. Do not access directly or override. Use the accessor or create methods instead.
protected MouseListener mouseListener
This protected field is implementation specific. Do not access directly or override. Use the accessor or create methods instead.
getMouseListener()
, createMouseListener()
protected KeyListener keyListener
This protected field is implementation specific. Do not access directly or override. Use the accessor or create methods instead.
getKeyListener()
, createKeyListener()
protected ListSelectionListener listSelectionListener
This protected field is implementation specific. Do not access directly or override. Use the create method instead.
createListSelectionListener()
protected MouseListener listMouseListener
This protected field is implementation specific. Do not access directly or override. Use the create method instead.
createListMouseListener()
protected MouseMotionListener listMouseMotionListener
This protected field is implementation specific. Do not access directly or override. Use the create method instead
createListMouseMotionListener()
protected PropertyChangeListener propertyChangeListener
This protected field is implementation specific. Do not access directly or override. Use the create method instead
createPropertyChangeListener()
protected ListDataListener listDataListener
This protected field is implementation specific. Do not access directly or override. Use the create method instead
createListDataListener()
protected ItemListener itemListener
This protected field is implementation specific. Do not access directly or override. Use the create method instead
createItemListener()
protected Timer autoscrollTimer
This protected field is implementation specific. Do not access directly or override.
protected boolean hasEntered
protected boolean isAutoScrolling
protected int scrollDirection
protected static final int SCROLL_UP
protected static final int SCROLL_DOWN
public BasicComboPopup(JComboBox combo)
public void show()
Implementation of ComboPopup.show().
show
in interface ComboPopup
show
in class Component
public void hide()
Implementation of ComboPopup.hide().
hide
in interface ComboPopup
hide
in class JComponent
public JList getList()
Implementation of ComboPopup.getList().
getList
in interface ComboPopup
public MouseListener getMouseListener()
Implementation of ComboPopup.getMouseListener().
getMouseListener
in interface ComboPopup
MouseListener
or nullComboPopup.getMouseListener()
public MouseMotionListener getMouseMotionListener()
Implementation of ComboPopup.getMouseMotionListener().
getMouseMotionListener
in interface ComboPopup
MouseMotionListener
or nullComboPopup.getMouseMotionListener()
public KeyListener getKeyListener()
Implementation of ComboPopup.getKeyListener().
getKeyListener
in interface ComboPopup
KeyListener
or nullComboPopup.getKeyListener()
public void uninstallingUI()
Called when the UI is uninstalling. Since this popup isn't in the component tree, it won't get it's uninstallUI() called. It removes the listeners that were added in addComboBoxListeners().
uninstallingUI
in interface ComboPopup
protected void uninstallComboBoxModelListeners(ComboBoxModel model)
Removes the listeners from the combo box model
model
- The combo box model to install listenersinstallComboBoxModelListeners(javax.swing.ComboBoxModel)
protected void uninstallKeyboardActions()
protected void firePopupMenuWillBecomeVisible()
Description copied from class: JPopupMenu
Notifies PopupMenuListener
s that this popup menu will become visible.
firePopupMenuWillBecomeVisible
in class JPopupMenu
protected void firePopupMenuWillBecomeInvisible()
Description copied from class: JPopupMenu
Notifies PopupMenuListener
s that this popup menu will become invisible.
firePopupMenuWillBecomeInvisible
in class JPopupMenu
protected void firePopupMenuCanceled()
Description copied from class: JPopupMenu
Notifies PopupMenuListeners
that this popup menu is cancelled.
firePopupMenuCanceled
in class JPopupMenu
protected MouseListener createMouseListener()
Creates a listener that will watch for mouse-press and release events on the combo box. Warning: When overriding this method, make sure to maintain the existing behavior.
MouseListener
which will be added to the combo box or nullprotected MouseMotionListener createMouseMotionListener()
Creates the mouse motion listener which will be added to the combo box. Warning: When overriding this method, make sure to maintain the existing behavior.
MouseMotionListener
which will be added to the combo box or nullprotected KeyListener createKeyListener()
Creates the key listener that will be added to the combo box. If this method returns null then it will not be added to the combo box.
KeyListener
or nullprotected ListSelectionListener createListSelectionListener()
Creates a list selection listener that watches for selection changes in the popup's list. If this method returns null then it will not be added to the popup list.
ListSelectionListener
or nullprotected ListDataListener createListDataListener()
Creates a list data listener which will be added to the ComboBoxModel
. If this method returns null then it will not be added to the combo box model.
ListDataListener
or nullprotected MouseListener createListMouseListener()
Creates a mouse listener that watches for mouse events in the popup's list. If this method returns null then it will not be added to the combo box.
MouseListener
or nullprotected MouseMotionListener createListMouseMotionListener()
Creates a mouse motion listener that watches for mouse motion events in the popup's list. If this method returns null then it will not be added to the combo box.
MouseMotionListener
or nullprotected PropertyChangeListener createPropertyChangeListener()
Creates a PropertyChangeListener
which will be added to the combo box. If this method returns null then it will not be added to the combo box.
PropertyChangeListener
or nullprotected ItemListener createItemListener()
Creates an ItemListener
which will be added to the combo box. If this method returns null then it will not be added to the combo box.
Subclasses may override this method to return instances of their own ItemEvent handlers.
ItemListener
or nullprotected JList createList()
Creates the JList used in the popup to display the items in the combo box model. This method is called when the UI class is created.
JList
used to display the combo box itemsprotected void configureList()
Configures the list which is used to hold the combo box items in the popup. This method is called when the UI class is created.
createList()
protected void installListListeners()
Adds the listeners to the list control.
protected JScrollPane createScroller()
Creates the scroll pane which houses the scrollable list.
protected void configureScroller()
Configures the scrollable portion which holds the list within the combo box popup. This method is called when the UI class is created.
protected void configurePopup()
Configures the popup portion of the combo box. This method is called when the UI class is created.
protected void installComboBoxListeners()
This method adds the necessary listeners to the JComboBox.
protected void installComboBoxModelListeners(ComboBoxModel model)
Installs the listeners on the combo box model. Any listeners installed on the combo box model should be removed in uninstallComboBoxModelListeners
.
model
- The combo box model to install listenersuninstallComboBoxModelListeners(javax.swing.ComboBoxModel)
protected void installKeyboardActions()
public boolean isFocusTraversable()
Overridden to unconditionally return false.
isFocusTraversable
in class Component
true
if this Component
is focusable; false
otherwiseComponent.setFocusable(boolean)
protected void startAutoScrolling(int direction)
This protected method is implementation specific and should be private. do not call or override.
protected void stopAutoScrolling()
This protected method is implementation specific and should be private. do not call or override.
protected void autoScrollUp()
This protected method is implementation specific and should be private. do not call or override.
protected void autoScrollDown()
This protected method is implementation specific and should be private. do not call or override.
public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this BasicComboPopup. The AccessibleContext will have its parent set to the ComboBox.
getAccessibleContext
in interface Accessible
getAccessibleContext
in class JPopupMenu
protected void delegateFocus(MouseEvent e)
This is is a utility method that helps event handlers figure out where to send the focus when the popup is brought up. The standard implementation delegates the focus to the editor (if the combo box is editable) or to the JComboBox if it is not editable.
protected void togglePopup()
Makes the popup visible if it is hidden and makes it hidden if it is visible.
protected MouseEvent convertMouseEvent(MouseEvent e)
protected int getPopupHeightForRowCount(int maxRowCount)
Retrieves the height of the popup based on the current ListCellRenderer and the maximum row count.
protected Rectangle computePopupBounds(int px, int py, int pw, int ph)
Calculate the placement and size of the popup portion of the combo box based on the combo box location and the enclosing screen bounds. If no transformations are required, then the returned rectangle will have the same values as the parameters.
px
- starting x locationpy
- starting y locationpw
- starting widthph
- starting heightprotected void updateListBoxSelectionForEvent(MouseEvent anEvent, boolean shouldScroll)
A utility method used by the event listeners. Given a mouse event, it changes the list selection to the list item below the mouse.
© 1993–2017, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.