模块 java.desktop

类 BasicOptionPaneUI

已知子类:
SynthOptionPaneUI

public class BasicOptionPaneUI extends OptionPaneUI
提供 JOptionPane 的基本外观。 BasicMessagePaneUI 提供了一种将图标、消息和按钮放入 Container 的方法。通常,布局如下所示:
    ------------------
    | i | message  |
    | c | message  |
    | o | message  |
    | n | message  |
    ------------------
    |   buttons  |
    |________________|
 
图标是 Icon 的一个实例,它被包裹在 JLabel 中。该消息是一个不透明对象,并进行以下测试:如果消息是 Component,则将其添加到 Container,如果它是 Icon,则将其包装在 JLabel 内并添加到 Container,否则将其包装在 JLabel 内。

当选项窗格的 ComponentOrientation 属性是水平的,从左到右时,使用上面的布局。布局将针对其他方向进行适当调整。

Container、消息、图标和按钮都是由抽象方法确定的。

  • 字段详细信息

    • MinimumWidth

      public static final int MinimumWidth
      JOptionPane 的最小宽度。
      参见:
    • MinimumHeight

      public static final int MinimumHeight
      JOptionPane 的最小高度。
      参见:
    • optionPane

      protected JOptionPane  optionPane
      JOptionPane 接收器正在为其提供外观。
    • minimumSize

      protected Dimension  minimumSize
      JOptionPane 的大小。
    • inputComponent

      protected JComponent  inputComponent
      如果 optionPane.getWantsInput() 返回 true,则 JComponent 提供输入。
    • initialFocusComponent

      protected Component  initialFocusComponent
      在使用 selectInitialValue 发送消息时接收焦点的组件。
    • hasCustomComponents

      protected boolean hasCustomComponents
      如果 Component 包含在消息或按钮中,则在 validateComponent 中将其设置为 true。
    • propertyChangeListener

      protected PropertyChangeListener  propertyChangeListener
      PropertyChangeListener 的实例。
  • 构造方法详细信息

    • BasicOptionPaneUI

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

    • createUI

      public static ComponentUI  createUI(JComponent  x)
      创建一个新的 BasicOptionPaneUI 实例。
      参数:
      x - 组件
      返回:
      一个新的 BasicOptionPaneUI 实例
    • installUI

      public void installUI(JComponent  c)
      将接收器安装为传入的 JOptionPane 的 L&F。
      重写:
      installUI 在类 ComponentUI
      参数:
      c - 正在安装此 UI 委托的组件
      参见:
    • uninstallUI

      public void uninstallUI(JComponent  c)
      从传入的拆分窗格的 L&F 控制器中删除接收器。
      重写:
      uninstallUI 在类 ComponentUI
      参数:
      c - 从中删除此 UI 委托的组件;这个参数经常被忽略,但如果 UI 对象是无状态的并且由多个组件共享,则可能会被使用
      参见:
    • installDefaults

      protected void installDefaults()
      安装默认属性。
    • uninstallDefaults

      protected void uninstallDefaults()
      卸载默认属性。
    • installComponents

      protected void installComponents()
      注册组件。
    • uninstallComponents

      protected void uninstallComponents()
      注销组件。
    • createLayoutManager

      protected LayoutManager  createLayoutManager()
      返回布局管理器。
      返回:
      布局管理器
    • installListeners

      protected void installListeners()
      注册听众。
    • uninstallListeners

      protected void uninstallListeners()
      注销听众。
    • createPropertyChangeListener

      protected PropertyChangeListener  createPropertyChangeListener()
      返回 PropertyChangeListener 的实例。
      返回:
      PropertyChangeListener 的实例
    • installKeyboardActions

      protected void installKeyboardActions()
      注册键盘操作。
    • uninstallKeyboardActions

      protected void uninstallKeyboardActions()
      注销键盘操作。
    • getMinimumOptionPaneSize

      public Dimension  getMinimumOptionPaneSize()
      返回选项窗格应具有的最小大小。主要为希望提供不同最小尺寸的子类提供。
      返回:
      选项面板的最小尺寸
    • getPreferredSize

      public Dimension  getPreferredSize(JComponent  c)
      如果 c 是包含接收器的 JOptionPane,则返回的首选大小是 JOptionPaneLayoutManagergetMinimumOptionPaneSize 的首选大小的最大值。
      重写:
      getPreferredSize 在类 ComponentUI
      参数:
      c - 正在查询其首选大小的组件;这个参数经常被忽略,但如果 UI 对象是无状态的并且由多个组件共享,则可能会被使用
      返回:
      一个 Dimension 对象,包含适合外观和感觉的给定组件的首选大小
      参见:
    • createMessageArea

      protected Container  createMessageArea()
      installComponents 发送消息以创建包含消息正文的 Container。该图标是通过调用 addIcon 创建的。
      返回:
      Container 的实例
    • addMessageComponents

      protected void addMessageComponents(Container  container, GridBagConstraints  cons, Object  msg, int maxll, boolean internallyCreated)
      创建适当的对象来表示 msg 并将其放入 container 中。如果msgComponent的实例,则直接添加;如果它是 Icon ,则创建一个 JLabel 来表示它;否则,为字符串创建一个 JLabel。如果 msg 是一个 Object[],这个方法将被子对象递归调用。 internallyCreatedtrue 如果 msgComponent 的实例并且是通过此方法在内部创建的(仅当 internallyCreatedfalse 时才用于正确设置 hasCustomComponents)。
      参数:
      container - 一个容器
      cons - GridBagConstraints 的实例
      msg - 一条消息
      maxll - 最大长度
      internallyCreated - true 如果组件是内部创建的
    • getMessage

      protected Object  getMessage()
      JOptionPane 返回要显示的消息,接收器为其提供外观。
      返回:
      要显示的消息
    • addIcon

      protected void addIcon(Container  top)
      创建并添加一个表示从 getIcon 返回到 top 的图标的 JLabel。这是来自 createMessageArea 的消息。
      参数:
      top - 一个容器
    • getIcon

      protected Icon  getIcon()
      JOptionPane 返回接收器为其提供外观的图标,或从 getDefaultIcon 返回的默认图标。
      返回:
      图标
    • getIconForType

      protected Icon  getIconForType(int messageType)
      返回用于传入类型的图标。
      参数:
      messageType - 一种消息
      返回:
      用于传入类型的图标
    • getMaxCharactersPerLineCount

      protected int getMaxCharactersPerLineCount()
      返回放置在一行中的最大字符数。
      返回:
      放置在一行中的最大字符数
    • burstStringInto

      protected void burstStringInto(Container  c, String  d, int maxll)
      递归地创建新的 JLabel 实例来表示 d 。每个 JLabel 实例都添加到 c
      参数:
      c - 一个容器
      d - 一段文字
      maxll - 文本的最大长度
    • createSeparator

      protected Container  createSeparator()
      返回一个分隔符。
      返回:
      分隔符
    • createButtonArea

      protected Container  createButtonArea()
      创建并返回一个包含按钮的 Container。这些按钮是通过调用 getButtons 创建的。
      返回:
      包含按钮的 Container
    • addButtonComponents

      protected void addButtonComponents(Container  container, Object [] buttons, int initialIndex)
      创建适当的对象来表示 buttons 中的每个对象并将其添加到 container 。这与 addMessageComponents 的不同之处在于它将在 buttons 上递归,并且如果按钮不是组件,它将创建 JButton 的实例。
      参数:
      container - 一个容器
      buttons - 一组按钮
      initialIndex - 初始索引
    • createButtonActionListener

      protected ActionListener  createButtonActionListener(int buttonIndex)
      构造 ButtonActionListener 的新实例。
      参数:
      buttonIndex - 按钮的索引
      返回:
      ButtonActionListener 的新实例
    • getButtons

      protected Object [] getButtons()
      返回按钮以从 JOptionPane 接收器提供外观和感觉。如果 JOptionPane 设置了选项,则将提供它们,否则如果选项类型为 YES_NO_OPTION ,则返回 yesNoOptions,如果类型为 YES_NO_CANCEL_OPTION 则返回 yesNoCancelOptions,否则返回 defaultButtons
      返回:
      从 JOptionPane 显示的按钮
    • getSizeButtonsToSameWidth

      protected boolean getSizeButtonsToSameWidth()
      返回 true ,基本 L&F 希望所有按钮具有相同的宽度。
      返回:
      true 如果所有的按钮应该有相同的宽度
    • getInitialValueIndex

      protected int getInitialValueIndex()
      将初始索引返回到要选择的按钮中。该索引是根据 JOptionPane 的初始值和 JOptionPane 的选项或 0 计算得出的。
      返回:
      初始索引到要选择的按钮中
    • resetInputValue

      protected void resetInputValue()
      在选项窗格中设置输入值,接收器根据 inputComponent 中的值为其提供外观。
    • selectInitialValue

      public void selectInitialValue(JOptionPane  op)
      如果 inputComponent 不为空,则请求焦点在它上面,否则请求焦点在默认值上
      指定者:
      selectInitialValue 在类 OptionPaneUI
      参数:
      op - 一个 JOptionPane
    • containsCustomComponents

      public boolean containsCustomComponents(JOptionPane  op)
      如果在最后一次调用 validateComponent 时消息或按钮包含 Component 的子类,则返回 true。
      指定者:
      containsCustomComponents 在类 OptionPaneUI
      参数:
      op - 一个 JOptionPane
      返回:
      true 如果给定的 JOptionPane 包含用户创建的 Component s