java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.OptionPaneUI
javax.swing.plaf.basic.BasicOptionPaneUI
- 已知子类:
SynthOptionPaneUI
提供
JOptionPane
的基本外观。 BasicMessagePaneUI
提供了一种将图标、消息和按钮放入 Container
的方法。通常,布局如下所示:
------------------ | i | message | | c | message | | o | message | | n | message | ------------------ | buttons | |________________|图标是
Icon
的一个实例,它被包裹在 JLabel
中。该消息是一个不透明对象,并进行以下测试:如果消息是 Component
,则将其添加到 Container
,如果它是 Icon
,则将其包装在 JLabel
内并添加到 Container
,否则将其包装在 JLabel
内。
当选项窗格的 ComponentOrientation
属性是水平的,从左到右时,使用上面的布局。布局将针对其他方向进行适当调整。
Container
、消息、图标和按钮都是由抽象方法确定的。
-
内部类总结
内部类修饰符和类型类描述class
此类应被视为“受保护”的内部类。static class
ButtonAreaLayout
的行为方式与FlowLayout
类似。class
此类应被视为“受保护”的内部类。 -
字段摘要
字段修饰符和类型Field描述protected boolean
如果 Component 包含在消息或按钮中,则在 validateComponent 中将其设置为 true。protected Component
在使用 selectInitialValue 发送消息时接收焦点的组件。protected JComponent
如果 optionPane.getWantsInput() 返回 true,则 JComponent 提供输入。static final int
JOptionPane
的最小高度。protected Dimension
JOptionPane
的大小。static final int
JOptionPane
的最小宽度。protected JOptionPane
JOptionPane
接收器正在为其提供外观。protected PropertyChangeListener
PropertyChangeListener
的实例。 -
构造方法总结
构造方法 -
方法总结
修饰符和类型方法描述protected void
addButtonComponents
(Container container, Object[] buttons, int initialIndex) 创建适当的对象来表示buttons
中的每个对象并将其添加到container
。protected void
创建并添加一个表示从getIcon
返回到top
的图标的 JLabel。protected void
addMessageComponents
(Container container, GridBagConstraints cons, Object msg, int maxll, boolean internallyCreated) 创建适当的对象来表示msg
并将其放入container
中。protected void
burstStringInto
(Container c, String d, int maxll) 递归地创建新的JLabel
实例来表示d
。boolean
如果在最后一次调用 validateComponent 时消息或按钮包含 Component 的子类,则返回 true。protected ActionListener
createButtonActionListener
(int buttonIndex) 构造ButtonActionListener
的新实例。protected Container
创建并返回一个包含按钮的Container
。protected LayoutManager
返回布局管理器。protected Container
从installComponents
发送消息以创建包含消息正文的Container
。protected PropertyChangeListener
返回PropertyChangeListener
的实例。protected Container
返回一个分隔符。static ComponentUI
创建一个新的BasicOptionPaneUI
实例。protected Object[]
返回按钮以从JOptionPane
接收器提供外观和感觉。protected Icon
getIcon()
从JOptionPane
返回接收器为其提供外观的图标,或从getDefaultIcon
返回的默认图标。protected Icon
getIconForType
(int messageType) 返回用于传入类型的图标。protected int
将初始索引返回到要选择的按钮中。protected int
返回放置在一行中的最大字符数。protected Object
从JOptionPane
返回要显示的消息,接收器为其提供外观。返回选项窗格应具有的最小大小。如果c
是包含接收器的JOptionPane
,则返回的首选大小是JOptionPane
的LayoutManager
和getMinimumOptionPaneSize
的首选大小的最大值。protected boolean
返回true
,基本 L&F 希望所有按钮具有相同的宽度。protected void
注册组件。protected void
安装默认属性。protected void
注册键盘操作。protected void
注册听众。void
将接收器安装为传入的JOptionPane
的 L&F。protected void
在选项窗格中设置输入值,接收器根据 inputComponent 中的值为其提供外观。void
如果 inputComponent 不为空,则请求焦点在它上面,否则请求焦点在默认值上protected void
注销组件。protected void
卸载默认属性。protected void
注销键盘操作。protected void
注销听众。void
从传入的拆分窗格的 L&F 控制器中删除接收器。在类 javax.swing.plaf.ComponentUI 中声明的方法
contains, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, paint, update
-
字段详细信息
-
MinimumWidth
public static final int MinimumWidthJOptionPane
的最小宽度。- 参见:
-
MinimumHeight
public static final int MinimumHeightJOptionPane
的最小高度。- 参见:
-
optionPane
JOptionPane
接收器正在为其提供外观。 -
minimumSize
JOptionPane
的大小。 -
inputComponent
如果 optionPane.getWantsInput() 返回 true,则 JComponent 提供输入。 -
initialFocusComponent
在使用 selectInitialValue 发送消息时接收焦点的组件。 -
hasCustomComponents
protected boolean hasCustomComponents如果 Component 包含在消息或按钮中,则在 validateComponent 中将其设置为 true。 -
propertyChangeListener
PropertyChangeListener
的实例。
-
-
构造方法详细信息
-
BasicOptionPaneUI
public BasicOptionPaneUI()构造一个BasicOptionPaneUI
-
-
方法详情
-
createUI
创建一个新的BasicOptionPaneUI
实例。- 参数:
x
- 组件- 返回:
-
一个新的
BasicOptionPaneUI
实例
-
installUI
将接收器安装为传入的JOptionPane
的 L&F。- 重写:
installUI
在类ComponentUI
中- 参数:
c
- 正在安装此 UI 委托的组件- 参见:
-
uninstallUI
从传入的拆分窗格的 L&F 控制器中删除接收器。- 重写:
uninstallUI
在类ComponentUI
中- 参数:
c
- 从中删除此 UI 委托的组件;这个参数经常被忽略,但如果 UI 对象是无状态的并且由多个组件共享,则可能会被使用- 参见:
-
installDefaults
protected void installDefaults()安装默认属性。 -
uninstallDefaults
protected void uninstallDefaults()卸载默认属性。 -
installComponents
protected void installComponents()注册组件。 -
uninstallComponents
protected void uninstallComponents()注销组件。 -
createLayoutManager
返回布局管理器。- 返回:
- 布局管理器
-
installListeners
protected void installListeners()注册听众。 -
uninstallListeners
protected void uninstallListeners()注销听众。 -
createPropertyChangeListener
返回PropertyChangeListener
的实例。- 返回:
PropertyChangeListener
的实例
-
installKeyboardActions
protected void installKeyboardActions()注册键盘操作。 -
uninstallKeyboardActions
protected void uninstallKeyboardActions()注销键盘操作。 -
getMinimumOptionPaneSize
返回选项窗格应具有的最小大小。主要为希望提供不同最小尺寸的子类提供。- 返回:
- 选项面板的最小尺寸
-
getPreferredSize
如果c
是包含接收器的JOptionPane
,则返回的首选大小是JOptionPane
的LayoutManager
和getMinimumOptionPaneSize
的首选大小的最大值。- 重写:
getPreferredSize
在类ComponentUI
中- 参数:
c
- 正在查询其首选大小的组件;这个参数经常被忽略,但如果 UI 对象是无状态的并且由多个组件共享,则可能会被使用- 返回:
-
一个
Dimension
对象,包含适合外观和感觉的给定组件的首选大小 - 参见:
-
createMessageArea
从installComponents
发送消息以创建包含消息正文的Container
。该图标是通过调用addIcon
创建的。- 返回:
Container
的实例
-
addMessageComponents
protected void addMessageComponents(Container container, GridBagConstraints cons, Object msg, int maxll, boolean internallyCreated) 创建适当的对象来表示msg
并将其放入container
中。如果msg
是Component
的实例,则直接添加;如果它是Icon
,则创建一个JLabel
来表示它;否则,为字符串创建一个JLabel
。如果msg
是一个 Object[],这个方法将被子对象递归调用。internallyCreated
是true
如果msg
是Component
的实例并且是通过此方法在内部创建的(仅当internallyCreated
是false
时才用于正确设置hasCustomComponents
)。- 参数:
container
- 一个容器cons
-GridBagConstraints
的实例msg
- 一条消息maxll
- 最大长度internallyCreated
-true
如果组件是内部创建的
-
getMessage
从JOptionPane
返回要显示的消息,接收器为其提供外观。- 返回:
- 要显示的消息
-
addIcon
创建并添加一个表示从getIcon
返回到top
的图标的 JLabel。这是来自createMessageArea
的消息。- 参数:
top
- 一个容器
-
getIcon
从JOptionPane
返回接收器为其提供外观的图标,或从getDefaultIcon
返回的默认图标。- 返回:
- 图标
-
getIconForType
返回用于传入类型的图标。- 参数:
messageType
- 一种消息- 返回:
- 用于传入类型的图标
-
getMaxCharactersPerLineCount
protected int getMaxCharactersPerLineCount()返回放置在一行中的最大字符数。- 返回:
- 放置在一行中的最大字符数
-
burstStringInto
递归地创建新的JLabel
实例来表示d
。每个JLabel
实例都添加到c
。- 参数:
c
- 一个容器d
- 一段文字maxll
- 文本的最大长度
-
createSeparator
返回一个分隔符。- 返回:
- 分隔符
-
createButtonArea
创建并返回一个包含按钮的Container
。这些按钮是通过调用getButtons
创建的。- 返回:
-
包含按钮的
Container
-
addButtonComponents
创建适当的对象来表示buttons
中的每个对象并将其添加到container
。这与 addMessageComponents 的不同之处在于它将在buttons
上递归,并且如果按钮不是组件,它将创建 JButton 的实例。- 参数:
container
- 一个容器buttons
- 一组按钮initialIndex
- 初始索引
-
createButtonActionListener
构造ButtonActionListener
的新实例。- 参数:
buttonIndex
- 按钮的索引- 返回:
ButtonActionListener
的新实例
-
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
如果 inputComponent 不为空,则请求焦点在它上面,否则请求焦点在默认值上- 指定者:
selectInitialValue
在类OptionPaneUI
中- 参数:
op
- 一个JOptionPane
-
containsCustomComponents
如果在最后一次调用 validateComponent 时消息或按钮包含 Component 的子类,则返回 true。- 指定者:
containsCustomComponents
在类OptionPaneUI
中- 参数:
op
- 一个JOptionPane
- 返回:
true
如果给定的JOptionPane
包含用户创建的Component
s
-