模块 java.desktop

类 BasicComboBoxUI

已知子类:
MetalComboBoxUI , SynthComboBoxUI

public class BasicComboBoxUI extends ComboBoxUI
JComboBox 的基本 UI 实现。

组合框是一个复合组件,这意味着它是许多简单组件的集合。此类创建和管理组合框和组合框模型上的监听。这些监听更新用户界面以响应组合框的属性和状态的变化。

所有事件处理都由使用createxxxListener() 方法和内部类创建的监听器类处理。您可以通过覆盖 createxxxListener() 方法并提供您自己的事件监听器或从此类中提供的事件监听器进行子类化来更改此类的行为。

要添加特定操作,请覆盖 installKeyboardActions 以添加响应 KeyStroke 绑定的操作。见文章如何使用键绑定

  • 字段详细信息

    • comboBox

      protected JComboBox <Object > comboBox
      JComboBox 的实例。
    • hasFocus

      protected boolean hasFocus
      该受保护字段是特定于实现的。不要直接访问或重写。
    • listBox

      protected JList <Object > listBox
      此list用于绘制组合框中的当前项。
    • currentValuePane

      protected CellRendererPane  currentValuePane
      用于呈现组合框中当前选定的项目。它与弹出窗口的渲染没有任何关系。
    • editor

      protected Component  editor
      ComboBoxEditor 用于编辑的组件。
    • arrowButton

      protected JButton  arrowButton
      调用弹出窗口的箭头按钮。
    • keyListener

      protected KeyListener  keyListener
      该受保护字段是特定于实现的。不要直接访问或重写。改写监听构造方法。
      参见:
    • focusListener

      protected FocusListener  focusListener
      该受保护字段是特定于实现的。不要直接访问或重写。改写监听构造方法。
      参见:
    • propertyChangeListener

      protected PropertyChangeListener  propertyChangeListener
      该受保护字段是特定于实现的。不要直接访问或重写。改写监听构造方法。
      参见:
    • itemListener

      protected ItemListener  itemListener
      该受保护字段是特定于实现的。不要直接访问或重写。改写监听构造方法。
      参见:
    • popupMouseListener

      protected MouseListener  popupMouseListener
      MouseListener 监听事件。
    • popupMouseMotionListener

      protected MouseMotionListener  popupMouseMotionListener
      MouseMotionListener 监听事件。
    • popupKeyListener

      protected KeyListener  popupKeyListener
      KeyListener 监听事件。
    • listDataListener

      protected ListDataListener  listDataListener
      该受保护字段是特定于实现的。不要直接访问或重写。改写监听构造方法。
      参见:
    • isMinimumSizeDirty

      protected boolean isMinimumSizeDirty
      重新计算最小首选大小的标志。
    • cachedMinimumSize

      protected Dimension  cachedMinimumSize
      缓存的最小首选大小。
    • squareButton

      protected boolean squareButton
      指示组合框按钮是否应为方形。如果是正方形,则宽度和高度相等,并且都设置为组合的高度减去适当的insets。
      自从:
      1.7
    • padding

      protected Insets  padding
      如果指定,这些insets在布局和绘制组合框中的“选定”项目时充当单元格渲染器周围的填充。这些insets添加到单元格渲染器指定的insets中。
      自从:
      1.7
  • 构造方法详细信息

    • BasicComboBoxUI

      public BasicComboBoxUI()
      构造一个 BasicComboBoxUI
  • 方法详情

    • 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 的实例
      参见:
    • createKeyListener

      protected KeyListener  createKeyListener()
      创建将添加到组合框的 KeyListener。如果此方法返回 null,则不会将其添加到组合框中。
      返回:
      实例 KeyListener 或 null
    • createFocusListener

      protected FocusListener  createFocusListener()
      创建将添加到组合框的 FocusListener。如果此方法返回 null,则不会将其添加到组合框中。
      返回:
      FocusListener 的实例或 null
    • createListDataListener

      protected ListDataListener  createListDataListener()
      创建一个将添加到 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 用于组合框
      参见:
    • createEditor

      protected ComboBoxEditor  createEditor()
      创建将在可编辑组合框中使用的默认编辑器。仅当未使用 setEditor 显式设置编辑器时,才会使用默认编辑器。
      返回:
      一个 ComboBoxEditor 用于组合框
      参见:
    • installComponents

      protected void installComponents()
      创建并初始化组成聚合组合框的组件。此方法作为 UI 安装过程的一部分被调用。
    • uninstallComponents

      protected void uninstallComponents()
      组成组合框的聚合组件未注册且未初始化。此方法作为 UI 卸载过程的一部分被调用。
    • addEditor

      public void addEditor()
      此公共方法是特定于实现的,应该是私有的。请勿调用或覆盖。要实现特定的编辑器,请创建自定义 ComboBoxEditor
      参见:
    • removeEditor

      public void removeEditor()
      此公共方法是特定于实现的,应该是私有的。请勿调用或重写。
      参见:
    • configureEditor

      protected void configureEditor()
      这个受保护的方法是特定于实现的,应该是私有的。请勿调用或重写。
      参见:
    • unconfigureEditor

      protected void unconfigureEditor()
      这个受保护的方法是特定于实现的,应该是私有的。请勿调用或重写。
      参见:
    • configureArrowButton

      public void configureArrowButton()
      此公共方法是特定于实现的,应该是私有的。请勿调用或重写。
      参见:
    • unconfigureArrowButton

      public void unconfigureArrowButton()
      此公共方法是特定于实现的,应该是私有的。请勿调用或重写。
      参见:
    • createArrowButton

      protected JButton  createArrowButton()
      创建一个按钮,用作显示或隐藏组合框弹出部分的控件。
      返回:
      代表弹出控件的按钮
    • isPopupVisible

      public boolean isPopupVisible(JComboBox <?> c)
      判断弹出窗口是否可见。
      指定者:
      isPopupVisible 在类 ComboBoxUI
      参数:
      c - 一个 JComboBox
      返回:
      如果 JComboBox 的弹出窗口可见,则为真
    • setPopupVisible

      public void setPopupVisible(JComboBox <?> c, boolean v)
      隐藏弹出窗口。
      指定者:
      setPopupVisible 在类 ComboBoxUI
      参数:
      c - 一个 JComboBox
      v - 一个 boolean 确定弹出窗口的可见性
    • isFocusTraversable

      public boolean isFocusTraversable(JComboBox <?> c)
      确定 JComboBox 是否可遍历焦点。如果 JComboBox 是可编辑的,则返回 false,否则返回 true。
      指定者:
      isFocusTraversable 在类 ComboBoxUI
      参数:
      c - 一个 JComboBox
      返回:
      如果给定的 JComboBox 是可遍历的,则为真
    • getMinimumSize

      public Dimension  getMinimumSize(JComponent  c)
      最小尺寸是显示区域加上insets加上按钮的尺寸。
      重写:
      getMinimumSize 在类 ComponentUI
      参数:
      c - 正在查询最小尺寸的组件;这个参数经常被忽略,但如果 UI 对象是无状态的并且由多个组件共享,则可能会被使用
      返回:
      Dimension 对象或 null
      参见:
    • getBaseline

      public int getBaseline(JComponent  c, int width, int height)
      返回基线。
      重写:
      getBaseline 在类 ComponentUI
      参数:
      c - JComponent 正在请求基线
      width - 获取基线的宽度
      height - 获取基线的高度
      返回:
      基线或值 < 0 表示没有合理的基线
      抛出:
      NullPointerException - 如果 cnull
      IllegalArgumentException - 如果宽度或高度 < 0
      自从:
      1.6
      参见:
    • getBaselineResizeBehavior

      public Component.BaselineResizeBehavior  getBaselineResizeBehavior(JComponent  c)
      返回一个枚举,指示组件的基线如何随着大小的变化而变化。
      重写:
      getBaselineResizeBehavior 在类 ComponentUI
      参数:
      c - JComponent 返回基线调整大小行为
      返回:
      一个枚举,指示基线如何随着组件大小的变化而变化
      抛出:
      NullPointerException - 如果 cnull
      自从:
      1.6
      参见:
    • 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。
      返回:
      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

      protected Dimension  getDisplaySize()
      返回显示区域的计算大小。显示区域是显示所选项目的组合框部分。如果已设置,此方法将使用原型显示值。

      对于具有大量项目的组合框,建议使用原型显示值以显着加快显示大小计算。

      返回:
      根据组合框项目计算的显示区域的大小
      参见:
    • getSizeForComponent

      protected Dimension  getSizeForComponent(Component  comp)
      返回组件用作单元格渲染器时的大小。
      参数:
      comp - 一个 Component 检查
      返回:
      组件的大小
      自从:
      1.7
    • installKeyboardActions

      protected void installKeyboardActions()
      将键盘操作添加到 JComboBox。已经提供了对 enter 和 esc 的操作。根据需要添加更多操作。
    • uninstallKeyboardActions

      protected void uninstallKeyboardActions()
      移除焦点 InputMap 和 ActionMap。