Class BasicComboPopup
- All Implemented Interfaces:
-
ImageObserver
,MenuContainer
,Serializable
,Accessible
,MenuElement
,ComboPopup
- Direct Known Subclasses:
MetalComboBoxUI.MetalComboPopup
public class BasicComboPopup extends JPopupMenu implements ComboPopup
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
.
Nested Class Summary
Modifier and Type | Class | 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. |
Nested classes/interfaces declared in class javax.swing.JPopupMenu
JPopupMenu.AccessibleJPopupMenu, JPopupMenu.Separator
Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Field Summary
Modifier and Type | Field | Description |
---|---|---|
protected Timer |
autoscrollTimer |
This protected field is implementation specific. |
protected JComboBox<Object> |
comboBox |
The instance of JComboBox . |
protected boolean |
hasEntered |
true if the mouse cursor is in the popup. |
protected boolean |
isAutoScrolling |
If true the auto-scrolling is enabled. |
protected ItemListener |
itemListener |
This protected field is implementation specific. |
protected KeyListener |
keyListener |
This protected field is implementation specific. |
protected JList<Object> |
list |
This protected field is implementation specific. |
protected ListDataListener |
listDataListener |
This protected field is implementation specific. |
protected MouseListener |
listMouseListener |
This protected field is implementation specific. |
protected MouseMotionListener |
listMouseMotionListener |
This protected field is implementation specific. |
protected ListSelectionListener |
listSelectionListener |
This protected field is implementation specific. |
protected MouseListener |
mouseListener |
This protected field is implementation specific. |
protected MouseMotionListener |
mouseMotionListener |
This protected field is implementation specific. |
protected PropertyChangeListener |
propertyChangeListener |
This protected field is implementation specific. |
protected static final int |
SCROLL_DOWN |
The direction of scrolling down. |
protected static final int |
SCROLL_UP |
The direction of scrolling up. |
protected int |
scrollDirection |
The direction of scrolling. |
protected JScrollPane |
scroller |
This protected field is implementation specific. |
protected boolean |
valueIsAdjusting |
As of Java 2 platform v1.4 this previously undocumented field is no longer used. |
Fields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor Summary
Constructor | Description |
---|---|
BasicComboPopup |
Constructs a new instance of BasicComboPopup . |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
protected void |
autoScrollDown() |
This protected method is implementation specific and should be private. |
protected void |
autoScrollUp() |
This protected method is implementation specific and should be private. |
protected Rectangle |
computePopupBounds |
Calculate the placement and size of the popup portion of the combo box based on the combo box location and the enclosing screen bounds. |
protected void |
configureList() |
Configures the list which is used to hold the combo box items in the popup. |
protected void |
configurePopup() |
Configures the popup portion of the combo box. |
protected void |
configureScroller() |
Configures the scrollable portion which holds the list within the combo box popup. |
protected MouseEvent |
convertMouseEvent |
Converts mouse event. |
protected ItemListener |
createItemListener() |
Creates an ItemListener which will be added to the combo box. |
protected KeyListener |
createKeyListener() |
Creates the key listener that will be added to the combo box. |
protected JList<Object> |
createList() |
Creates the JList used in the popup to display the items in the combo box model. |
protected ListDataListener |
createListDataListener() |
Creates a list data listener which will be added to the ComboBoxModel . |
protected MouseListener |
createListMouseListener() |
Creates a mouse listener that watches for mouse events in the popup's list. |
protected MouseMotionListener |
createListMouseMotionListener() |
Creates a mouse motion listener that watches for mouse motion events in the popup's list. |
protected ListSelectionListener |
createListSelectionListener() |
Creates a list selection listener that watches for selection changes in the popup's list. |
protected MouseListener |
createMouseListener() |
Creates a listener that will watch for mouse-press and release events on the combo box. |
protected MouseMotionListener |
createMouseMotionListener() |
Creates the mouse motion listener which will be added to the combo box. |
protected PropertyChangeListener |
createPropertyChangeListener() |
Creates a PropertyChangeListener which will be added to the combo box. |
protected JScrollPane |
createScroller() |
Creates the scroll pane which houses the scrollable list. |
protected void |
delegateFocus |
This is a utility method that helps event handlers figure out where to send the focus when the popup is brought up. |
AccessibleContext |
getAccessibleContext() |
Gets the AccessibleContext associated with this BasicComboPopup. |
KeyListener |
getKeyListener() |
Implementation of ComboPopup.getKeyListener(). |
JList<Object> |
getList() |
Implementation of ComboPopup.getList(). |
MouseListener |
getMouseListener() |
Implementation of ComboPopup.getMouseListener(). |
MouseMotionListener |
getMouseMotionListener() |
Implementation of ComboPopup.getMouseMotionListener(). |
protected int |
getPopupHeightForRowCount |
Retrieves the height of the popup based on the current ListCellRenderer and the maximum row count. |
void |
hide() |
Implementation of ComboPopup.hide(). |
protected void |
installComboBoxListeners() |
This method adds the necessary listeners to the JComboBox. |
protected void |
installComboBoxModelListeners |
Installs the listeners on the combo box model. |
protected void |
installKeyboardActions() |
Registers keyboard actions. |
protected void |
installListListeners() |
Adds the listeners to the list control. |
boolean |
isFocusTraversable() |
Overridden to unconditionally return false. |
void |
show() |
Implementation of ComboPopup.show(). |
protected void |
startAutoScrolling |
This protected method is implementation specific and should be private. |
protected void |
stopAutoScrolling() |
This protected method is implementation specific and should be private. |
protected void |
togglePopup() |
Makes the popup visible if it is hidden and makes it hidden if it is visible. |
protected void |
uninstallComboBoxModelListeners |
Removes the listeners from the combo box model |
void |
uninstallingUI() |
Called when the UI is uninstalling. |
protected void |
uninstallKeyboardActions() |
Unregisters keyboard actions. |
protected void |
updateListBoxSelectionForEvent |
A utility method used by the event listeners. |
Methods declared in class javax.swing.JPopupMenu
add, add, add, addMenuKeyListener, addPopupMenuListener, addSeparator, createActionChangeListener, createActionComponent, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getComponent, getComponentAtIndex, getComponentIndex, getDefaultLightWeightPopupEnabled, getInvoker, getLabel, getMargin, getMenuKeyListeners, getPopupMenuListeners, getSelectionModel, getSubElements, getUI, getUIClassID, insert, insert, isBorderPainted, isLightWeightPopupEnabled, isPopupTrigger, isVisible, menuSelectionChanged, pack, paintBorder, paramString, processKeyEvent, processKeyEvent, processMouseEvent, remove, removeMenuKeyListener, removePopupMenuListener, setBorderPainted, setDefaultLightWeightPopupEnabled, setInvoker, setLabel, setLightWeightPopupEnabled, setLocation, setPopupSize, setPopupSize, setSelected, setSelectionModel, setUI, setVisible, show, updateUI
Methods declared in class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, 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, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update
Methods declared in 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, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods declared in class java.awt.Component
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, firePropertyChange, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods declared in interface javax.swing.plaf.basic.ComboPopup
isVisible
Field Details
comboBox
protected JComboBox<Object> comboBox
JComboBox
.list
protected JList<Object> list
- See Also:
scroller
protected JScrollPane scroller
- See Also:
valueIsAdjusting
protected boolean valueIsAdjusting
mouseMotionListener
protected MouseMotionListener mouseMotionListener
mouseListener
protected MouseListener mouseListener
- See Also:
keyListener
protected KeyListener keyListener
- See Also:
listSelectionListener
protected ListSelectionListener listSelectionListener
- See Also:
listMouseListener
protected MouseListener listMouseListener
- See Also:
listMouseMotionListener
protected MouseMotionListener listMouseMotionListener
- See Also:
propertyChangeListener
protected PropertyChangeListener propertyChangeListener
- See Also:
listDataListener
protected ListDataListener listDataListener
- See Also:
itemListener
protected ItemListener itemListener
- See Also:
autoscrollTimer
protected Timer autoscrollTimer
hasEntered
protected boolean hasEntered
true
if the mouse cursor is in the popup.isAutoScrolling
protected boolean isAutoScrolling
true
the auto-scrolling is enabled.scrollDirection
protected int scrollDirection
SCROLL_UP
protected static final int SCROLL_UP
- See Also:
SCROLL_DOWN
protected static final int SCROLL_DOWN
- See Also:
Constructor Details
BasicComboPopup
public BasicComboPopup(JComboBox<Object> combo)
BasicComboPopup
.- Parameters:
-
combo
- an instance ofJComboBox
Method Details
show
public void show()
- Specified by:
-
show
in interfaceComboPopup
- Overrides:
-
show
in classComponent
hide
public void hide()
- Specified by:
-
hide
in interfaceComboPopup
- Overrides:
-
hide
in classJComponent
getList
public JList<Object> getList()
- Specified by:
-
getList
in interfaceComboPopup
- Returns:
- the list that is being used to draw the items in the combo box
getMouseListener
public MouseListener getMouseListener()
- Specified by:
-
getMouseListener
in interfaceComboPopup
- Returns:
- a
MouseListener
or null - See Also:
getMouseMotionListener
public MouseMotionListener getMouseMotionListener()
- Specified by:
-
getMouseMotionListener
in interfaceComboPopup
- Returns:
- a
MouseMotionListener
or null - See Also:
getKeyListener
public KeyListener getKeyListener()
- Specified by:
-
getKeyListener
in interfaceComboPopup
- Returns:
- a
KeyListener
or null - See Also:
uninstallingUI
public void uninstallingUI()
- Specified by:
-
uninstallingUI
in interfaceComboPopup
uninstallComboBoxModelListeners
protected void uninstallComboBoxModelListeners(ComboBoxModel<?> model)
- Parameters:
-
model
- The combo box model to install listeners - See Also:
uninstallKeyboardActions
protected void uninstallKeyboardActions()
createMouseListener
protected MouseListener createMouseListener()
- Returns:
- a
MouseListener
which will be added to the combo box or null
createMouseMotionListener
protected MouseMotionListener createMouseMotionListener()
- Returns:
- a
MouseMotionListener
which will be added to the combo box or null
createKeyListener
protected KeyListener createKeyListener()
- Returns:
- a
KeyListener
or null
createListSelectionListener
protected ListSelectionListener createListSelectionListener()
- Returns:
- an instance of a
ListSelectionListener
or null
createListDataListener
protected ListDataListener createListDataListener()
ComboBoxModel
. If this method returns null then it will not be added to the combo box model.- Returns:
- an instance of a
ListDataListener
or null
createListMouseListener
protected MouseListener createListMouseListener()
- Returns:
- an instance of a
MouseListener
or null
createListMouseMotionListener
protected MouseMotionListener createListMouseMotionListener()
- Returns:
- an instance of a
MouseMotionListener
or null
createPropertyChangeListener
protected PropertyChangeListener createPropertyChangeListener()
PropertyChangeListener
which will be added to the combo box. If this method returns null then it will not be added to the combo box.- Returns:
- an instance of a
PropertyChangeListener
or null
createItemListener
protected ItemListener createItemListener()
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.
- Returns:
- an instance of an
ItemListener
or null
createList
protected JList<Object> createList()
- Returns:
- a
JList
used to display the combo box items
configureList
protected void configureList()
- See Also:
installListListeners
protected void installListListeners()
createScroller
protected JScrollPane createScroller()
- Returns:
- the scroll pane which houses the scrollable list
configureScroller
protected void configureScroller()
configurePopup
protected void configurePopup()
installComboBoxListeners
protected void installComboBoxListeners()
installComboBoxModelListeners
protected void installComboBoxModelListeners(ComboBoxModel<?> model)
uninstallComboBoxModelListeners
.- Parameters:
-
model
- The combo box model to install listeners - See Also:
installKeyboardActions
protected void installKeyboardActions()
isFocusTraversable
public boolean isFocusTraversable()
- Overrides:
-
isFocusTraversable
in classComponent
- Returns:
-
true
if thisComponent
is focusable;false
otherwise - See Also:
startAutoScrolling
protected void startAutoScrolling(int direction)
- Parameters:
-
direction
- the direction of scrolling
stopAutoScrolling
protected void stopAutoScrolling()
autoScrollUp
protected void autoScrollUp()
autoScrollDown
protected void autoScrollDown()
getAccessibleContext
public AccessibleContext getAccessibleContext()
- Specified by:
-
getAccessibleContext
in interfaceAccessible
- Overrides:
-
getAccessibleContext
in classJPopupMenu
- Returns:
- an AccessibleContext for the BasicComboPopup
- Since:
- 1.5
delegateFocus
protected void delegateFocus(MouseEvent e)
- Parameters:
-
e
- a mouse event
togglePopup
protected void togglePopup()
convertMouseEvent
protected MouseEvent convertMouseEvent(MouseEvent e)
- Parameters:
-
e
- a mouse event - Returns:
- converted mouse event
getPopupHeightForRowCount
protected int getPopupHeightForRowCount(int maxRowCount)
- Parameters:
-
maxRowCount
- the row count - Returns:
- the height of the popup
computePopupBounds
protected Rectangle computePopupBounds(int px, int py, int pw, int ph)
- Parameters:
-
px
- starting x location -
py
- starting y location -
pw
- starting width -
ph
- starting height - Returns:
- a rectangle which represents the placement and size of the popup
updateListBoxSelectionForEvent
protected void updateListBoxSelectionForEvent(MouseEvent anEvent, boolean shouldScroll)
- Parameters:
-
anEvent
- a mouse event -
shouldScroll
- iftrue
list should be scrolled.
© 1993, 2021, 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.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/plaf/basic/BasicComboPopup.html