- java.lang.Object
-
- javax.swing.plaf.ComponentUI
-
- javax.swing.plaf.ComboBoxUI
-
- javax.swing.plaf.basic.BasicComboBoxUI
-
- 已知直接子类:
-
MetalComboBoxUI,SynthComboBoxUI
public class BasicComboBoxUI extends ComboBoxUI
JComboBox的基本UI实现。组合框是一个复合组件,这意味着它是许多更简单组件的集合。 此类在组合框和组合框模型上创建和管理侦听器。 这些侦听器更新用户界面以响应组合框的属性和状态的更改。
所有事件处理都由使用
createxxxListener()方法和内部类创建的侦听器类处理。 您可以通过重写createxxxListener()方法并提供自己的事件侦听器或从此类中提供的子类化来更改此类的行为。对于添加特定操作,请在
installKeyboardActions上添加操作以响应KeyStroke绑定。 见文章How to Use Key Bindings
-
-
嵌套类汇总
嵌套类 变量和类型 类 描述 classBasicComboBoxUI.ComboBoxLayoutManager此布局管理器处理组合框的“标准”布局。classBasicComboBoxUI.FocusHandler当焦点丢失时,此侦听器会隐藏弹出窗口。classBasicComboBoxUI.ItemHandler此侦听器监视组合框中选择的更改。classBasicComboBoxUI.KeyHandler此侦听器检查键事件是否不是导航键。classBasicComboBoxUI.ListDataHandler这位听众会ComboBoxModel变化。classBasicComboBoxUI.PropertyChangeHandler此侦听器监视组合框中已更改的绑定属性。
-
字段汇总
字段 变量和类型 字段 描述 protected JButtonarrowButton调用弹出窗口的箭头按钮。protected DimensioncachedMinimumSize缓存的最小首选大小。protected JComboBox<Object>comboBoxJComboBox的实例。protected CellRendererPanecurrentValuePane用于在组合框中呈现当前选定的项目。protected Componenteditor@ {code ComboBoxEditor}用于编辑的组件。protected FocusListenerfocusListener此受保护字段是特定于实现的。protected booleanhasFocus此受保护字段是特定于实现的。protected booleanisMinimumSizeDirty重新计算最小首选大小的标志。protected ItemListeneritemListener此受保护字段是特定于实现的。protected KeyListenerkeyListener此受保护字段是特定于实现的。protected JList<Object>listBox此列表用于在组合框中绘制当前项目。protected ListDataListenerlistDataListener此受保护字段是特定于实现的。protected Insetspadding如果指定,则在布局和绘制组合框中的“selected”项时,这些insets充当单元格渲染器周围的填充。protected ComboPopuppopup用于显示弹出窗口的ComboPopup的实现。protected KeyListenerpopupKeyListenerKeyListener监听事件。protected MouseListenerpopupMouseListenerMouseListener监听事件。protected MouseMotionListenerpopupMouseMotionListenerMouseMotionListener监听事件。protected PropertyChangeListenerpropertyChangeListener此受保护字段是特定于实现的。protected booleansquareButton指示组合框按钮是否应为方形。
-
构造方法摘要
构造方法 构造器 描述 BasicComboBoxUI()
-
方法摘要
所有方法 静态方法 实例方法 具体的方法 变量和类型 方法 描述 voidaddEditor()此公共方法是特定于实现的,应该是私有的。voidconfigureArrowButton()此公共方法是特定于实现的,应该是私有的。protected voidconfigureEditor()此受保护的方法是特定于实现的,应该是私有的。protected JButtoncreateArrowButton()创建一个按钮,该按钮将用作控件以显示或隐藏组合框的弹出部分。protected ComboBoxEditorcreateEditor()创建将在可编辑组合框中使用的默认编辑器。protected FocusListenercreateFocusListener()创建一个FocusListener,它将被添加到组合框中。protected ItemListenercreateItemListener()创建一个ItemListener,它将被添加到组合框中。protected KeyListenercreateKeyListener()创建一个KeyListener,它将被添加到组合框中。protected LayoutManagercreateLayoutManager()创建一个布局管理器,用于管理组成组合框的组件。protected ListDataListenercreateListDataListener()创建将添加到ComboBoxModel的列表数据侦听ComboBoxModel。protected ComboPopupcreatePopup()创建组合框的弹出部分。protected PropertyChangeListenercreatePropertyChangeListener()创建一个PropertyChangeListener,它将被添加到组合框中。protected ListCellRenderer<Object>createRenderer()创建将在不可编辑的组合框中使用的默认渲染器。static ComponentUIcreateUI(JComponent c)构造一个BasicComboBoxUI的新实例。intgetBaseline(JComponent c, int width, int height)返回基线。Component.BaselineResizeBehaviorgetBaselineResizeBehavior(JComponent c)返回一个枚举,指示组件的基线如何随大小的变化而变化。protected DimensiongetDefaultSize()使用当前渲染器和字体返回组合框的空显示区域的默认大小。protected DimensiongetDisplaySize()返回显示区域的计算大小。protected InsetsgetInsets()获取JComboBox的insets。DimensiongetMinimumSize(JComponent c)最小尺寸是显示区域的大小加上插图加上按钮。protected DimensiongetSizeForComponent(Component comp)返回组件用作单元格渲染器时的大小。protected voidinstallComponents()创建并初始化组成聚合组合框的组件。protected voidinstallDefaults()将默认颜色,默认字体,默认渲染器和默认编辑器安装到JComboBox中。protected voidinstallKeyboardActions()将键盘操作添加到JComboBox。protected voidinstallListeners()为组合框及其模型创建并安装侦听器。booleanisFocusTraversable(JComboBox<?> c)确定JComboBox是否可以焦点遍历。protected booleanisNavigationKey(int keyCode)返回提供的keyCode是否映射到用于导航的键。booleanisPopupVisible(JComboBox<?> c)判断弹出窗口是否可见。voidpaintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)绘制当前选定的项目。voidpaintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)绘制当前所选项目的背景。protected RectanglerectangleForCurrentValue()返回为绘制当前所选项目而保留的区域。voidremoveEditor()此公共方法是特定于实现的,应该是私有的。protected voidselectNextPossibleValue()选择列表中的下一个项目。protected voidselectPreviousPossibleValue()选择列表中的上一项。voidsetPopupVisible(JComboBox<?> c, boolean v)隐藏弹出窗口。protected voidtoggleOpenClose()如果弹出窗口显示则隐藏弹出窗口,如果隐藏弹出窗口则显示弹出窗口。voidunconfigureArrowButton()此公共方法是特定于实现的,应该是私有的。protected voidunconfigureEditor()此受保护的方法是特定于实现的,应该是私有的。protected voiduninstallComponents()组成框的聚合组件未注册且未初始化。protected voiduninstallDefaults()从组合框中卸载默认颜色,默认字体,默认渲染器和默认编辑器。protected voiduninstallKeyboardActions()删除焦点InputMap和ActionMap。protected voiduninstallListeners()从组合框及其模型中删除已安装的侦听器。-
声明方法的类 javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getPreferredSize, installUI, paint, uninstallUI, update
-
-
-
-
字段详细信息
-
hasFocus
protected boolean hasFocus
此受保护字段是特定于实现的。 不要直接访问或覆盖。
-
currentValuePane
protected CellRendererPane currentValuePane
用于在组合框中呈现当前选定的项目。 它与弹出窗口的渲染没有任何关系。
-
popup
protected ComboPopup popup
用于显示弹出窗口的ComboPopup的实现。
-
editor
protected Component editor
@ {code ComboBoxEditor}用于编辑的组件。
-
arrowButton
protected JButton arrowButton
调用弹出窗口的箭头按钮。
-
keyListener
protected KeyListener keyListener
此受保护字段是特定于实现的。 不要直接访问或覆盖。 改为覆盖侦听器构造方法。- 另请参见:
-
createKeyListener()
-
focusListener
protected FocusListener focusListener
此受保护字段是特定于实现的。 不要直接访问或覆盖。 改为覆盖侦听器构造方法。- 另请参见:
-
createFocusListener()
-
propertyChangeListener
protected PropertyChangeListener propertyChangeListener
此受保护字段是特定于实现的。 不要直接访问或覆盖。 改为覆盖侦听器构造方法。
-
itemListener
protected ItemListener itemListener
此受保护字段是特定于实现的。 不要直接访问或覆盖。 改为覆盖侦听器构造方法。- 另请参见:
-
createItemListener()
-
popupMouseListener
protected MouseListener popupMouseListener
MouseListener侦听事件。
-
popupMouseMotionListener
protected MouseMotionListener popupMouseMotionListener
MouseMotionListener监听事件。
-
popupKeyListener
protected KeyListener popupKeyListener
KeyListener监听事件。
-
listDataListener
protected ListDataListener listDataListener
此受保护字段是特定于实现的。 不要直接访问或覆盖。 改为覆盖侦听器构造方法。- 另请参见:
-
createListDataListener()
-
isMinimumSizeDirty
protected boolean isMinimumSizeDirty
重新计算最小首选大小的标志。
-
cachedMinimumSize
protected Dimension cachedMinimumSize
缓存的最小首选大小。
-
squareButton
protected boolean squareButton
指示组合框按钮是否应为方形。 如果是square,则宽度和高度相等,并且都设置为组合的高度减去适当的insets。- 从以下版本开始:
- 1.7
-
padding
protected Insets padding
如果指定,则在布局和绘制组合框中的“selected”项时,这些insets充当单元格渲染器周围的填充。 这些插入添加到单元格渲染器指定的插入。- 从以下版本开始:
- 1.7
-
-
方法详细信息
-
createUI
public static ComponentUI createUI(JComponent c)
构造一个BasicComboBoxUI的新实例。- 参数
-
c- 一个组件 - 结果
-
BasicComboBoxUI的新实例
-
installDefaults
protected void installDefaults()
将默认颜色,默认字体,默认渲染器和默认编辑器安装到JComboBox中。
-
installListeners
protected void installListeners()
为组合框及其模型创建并安装侦听器。 安装UI时调用此方法。
-
uninstallDefaults
protected void uninstallDefaults()
从组合框中卸载默认颜色,默认字体,默认渲染器和默认编辑器。
-
uninstallListeners
protected void uninstallListeners()
从组合框及其模型中删除已安装的侦听器。 删除的侦听器的数量和类型以及此方法应与installListeners中添加的侦听器的数量和类型相同
-
createPopup
protected ComboPopup createPopup()
创建组合框的弹出部分。- 结果
-
ComboPopup一个实例 - 另请参见:
-
ComboPopup
-
createKeyListener
protected KeyListener createKeyListener()
创建一个KeyListener,它将被添加到组合框中。 如果此方法返回null,则不会将其添加到组合框中。- 结果
-
实例
KeyListener或null
-
createFocusListener
protected FocusListener createFocusListener()
创建一个FocusListener,它将被添加到组合框中。 如果此方法返回null,则不会将其添加到组合框中。- 结果
-
FocusListener的实例或null
-
createListDataListener
protected ListDataListener createListDataListener()
创建将添加到ComboBoxModel的列表数据侦听ComboBoxModel。 如果此方法返回null,则它将不会添加到组合框模型中。- 结果
-
ListDataListener的实例或null
-
createItemListener
protected ItemListener createItemListener()
创建一个ItemListener,它将被添加到组合框中。 如果此方法返回null,则不会将其添加到组合框中。子类可以重写此方法以返回其自己的ItemEvent处理程序的实例。
- 结果
-
ItemListener的实例或null
-
createPropertyChangeListener
protected PropertyChangeListener createPropertyChangeListener()
创建一个PropertyChangeListener,它将被添加到组合框中。 如果此方法返回null,则不会将其添加到组合框中。- 结果
-
PropertyChangeListener的实例或null
-
createLayoutManager
protected LayoutManager createLayoutManager()
创建一个布局管理器,用于管理组成组合框的组件。- 结果
- 布局管理器的一个实例
-
createRenderer
protected ListCellRenderer<Object> createRenderer()
创建将在不可编辑的组合框中使用的默认渲染器。 仅当未使用setRenderer显式设置渲染器时,才会使用默认渲染器。- 结果
-
用于组合框的
ListCellRender - 另请参见:
-
JComboBox.setRenderer(javax.swing.ListCellRenderer<? super E>)
-
createEditor
protected ComboBoxEditor createEditor()
创建将在可编辑组合框中使用的默认编辑器。 仅当未使用setEditor显式设置编辑器时,才会使用默认编辑器。- 结果
-
用于组合框的
ComboBoxEditor - 另请参见:
-
JComboBox.setEditor(javax.swing.ComboBoxEditor)
-
installComponents
protected void installComponents()
创建并初始化组成聚合组合框的组件。 此方法作为UI安装过程的一部分进行调用。
-
uninstallComponents
protected void uninstallComponents()
组成框的聚合组件未注册且未初始化。 此方法作为UI卸载过程的一部分进行调用。
-
addEditor
public void addEditor()
此公共方法是特定于实现的,应该是私有的。 不要打电话或覆盖。 要实现特定编辑器,请创建自定义ComboBoxEditor
-
removeEditor
public void removeEditor()
此公共方法是特定于实现的,应该是私有的。 不要打电话或覆盖。- 另请参见:
-
addEditor()
-
configureEditor
protected void configureEditor()
此受保护的方法是特定于实现的,应该是私有的。 不要打电话或覆盖。- 另请参见:
-
addEditor()
-
unconfigureEditor
protected void unconfigureEditor()
此受保护的方法是特定于实现的,应该是私有的。 不要打电话或覆盖。- 另请参见:
-
addEditor()
-
configureArrowButton
public void configureArrowButton()
此公共方法是特定于实现的,应该是私有的。 不要打电话或覆盖。- 另请参见:
-
createArrowButton()
-
unconfigureArrowButton
public void unconfigureArrowButton()
此公共方法是特定于实现的,应该是私有的。 不要打电话或覆盖。- 另请参见:
-
createArrowButton()
-
createArrowButton
protected JButton createArrowButton()
创建一个按钮,该按钮将用作控件以显示或隐藏组合框的弹出部分。- 结果
- 一个代表弹出控件的按钮
-
isPopupVisible
public boolean isPopupVisible(JComboBox<?> c)
判断弹出窗口是否可见。- Specified by:
-
isPopupVisible在类ComboBoxUI - 参数
-
c- aJComboBox - 结果
-
如果
JComboBox弹出窗口可见,JComboBoxtrue
-
setPopupVisible
public void setPopupVisible(JComboBox<?> c, boolean v)
隐藏弹出窗口。- Specified by:
-
setPopupVisible类ComboBoxUI - 参数
-
c- aJComboBox -
v-boolean确定弹出窗口的可见性
-
isFocusTraversable
public boolean isFocusTraversable(JComboBox<?> c)
确定JComboBox是否可以焦点遍历。 如果JComboBox是可编辑的,则返回false,否则返回true。- Specified by:
-
isFocusTraversable在类ComboBoxUI - 参数
-
c- aJComboBox - 结果
-
如果给定的
JComboBox是可遍历的,JComboBoxtrue
-
getMinimumSize
public Dimension getMinimumSize(JComponent c)
最小尺寸是显示区域的大小加上插图加上按钮。- 重写:
-
getMinimumSize在类ComponentUI - 参数
-
c- 正在查询其最小大小的组件; 此参数通常被忽略,但如果UI对象是无状态的并且由多个组件共享,则可以使用此参数 - 结果
-
Dimension对象或null - 另请参见:
-
JComponent.getMinimumSize(),LayoutManager.minimumLayoutSize(java.awt.Container),ComponentUI.getPreferredSize(javax.swing.JComponent)
-
getBaseline
public int getBaseline(JComponent c, int width, int height)
返回基线。- 重写:
-
getBaseline在类ComponentUI - 参数
-
c-JComponent正在申请基线 -
width- 获取基线的宽度 -
height- 获取基线的高度 - 结果
- 基线或值<0表示没有合理的基线
- 异常
-
NullPointerException- 如果c是null -
IllegalArgumentException- 如果宽度或高度<0 - 从以下版本开始:
- 1.6
- 另请参见:
-
JComponent.getBaseline(int, int)
-
getBaselineResizeBehavior
public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
返回一个枚举,指示组件的基线如何随大小的变化而变化。- 重写:
-
getBaselineResizeBehavior,类ComponentUI - 参数
-
c-JComponent返回基线调整大小的行为 - 结果
- 一个枚举,指示基线随组件大小的变化而变化的方式
- 异常
-
NullPointerException- 如果c是null - 从以下版本开始:
- 1.6
- 另请参见:
-
JComponent.getBaseline(int, int)
-
isNavigationKey
protected boolean isNavigationKey(int keyCode)
返回提供的keyCode是否映射到用于导航的键。 这用于通过仅将非导航键传递到预先输入机制来优化键输入。 如果子类更改了导航键,则应覆盖此类。- 参数
-
keyCode- 密钥代码 - 结果
-
true如果提供的keyCode映射到导航键
-
selectNextPossibleValue
protected void selectNextPossibleValue()
选择列表中的下一个项目。 如果当前所选项目已经是最后一项,则不会更改选择。
-
selectPreviousPossibleValue
protected void selectPreviousPossibleValue()
选择列表中的上一项。 如果当前所选项目已经是第一项,则不会更改选择。
-
toggleOpenClose
protected void toggleOpenClose()
如果弹出窗口显示则隐藏弹出窗口,如果隐藏弹出窗口则显示弹出窗口。
-
rectangleForCurrentValue
protected Rectangle rectangleForCurrentValue()
返回为绘制当前所选项目而保留的区域。- 结果
- 为绘制当前所选项目而保留的区域
-
getInsets
protected Insets getInsets()
获取JComboBox的insets。- 结果
- 插图
-
paintCurrentValue
public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
绘制当前选定的项目。- 参数
-
g-实例Graphics -
bounds- 要渲染的边界矩形 -
hasFocus- 很专注
-
paintCurrentValueBackground
public void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)
绘制当前所选项目的背景。- 参数
-
g-实例Graphics -
bounds- 要渲染的边界矩形 -
hasFocus- 很专注
-
getDefaultSize
protected Dimension getDefaultSize()
使用当前渲染器和字体返回组合框的空显示区域的默认大小。- 结果
- 空显示区域的大小
- 另请参见:
-
getDisplaySize()
-
getDisplaySize
protected Dimension getDisplaySize()
返回显示区域的计算大小。 显示区域是组合框中显示所选项目的部分。 如果已设置,此方法将使用原型显示值。对于具有非常少数量项目的组合框,建议使用原型显示值来显着加快显示尺寸计算。
- 结果
- 从组合框项目计算的显示区域的大小
- 另请参见:
-
JComboBox.setPrototypeDisplayValue(E)
-
getSizeForComponent
protected Dimension getSizeForComponent(Component comp)
返回组件用作单元格渲染器时的大小。- 参数
-
comp- 要检查Component - 结果
- 组件的大小
- 从以下版本开始:
- 1.7
-
installKeyboardActions
protected void installKeyboardActions()
将键盘操作添加到JComboBox。 已提供对enter和esc的操作。 根据需要添加更多操作。
-
uninstallKeyboardActions
protected void uninstallKeyboardActions()
删除焦点InputMap和ActionMap。
-
-