- java.lang.Object
-
- javax.swing.plaf.ComponentUI
-
- javax.swing.plaf.OptionPaneUI
-
- javax.swing.plaf.basic.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,消息,图标和按钮都是从抽象方法确定的。
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 描述 classBasicOptionPaneUI.ButtonActionListener这个类应该被视为一个“受保护”的内部类。static classBasicOptionPaneUI.ButtonAreaLayoutButtonAreaLayout行为类似于FlowLayout。classBasicOptionPaneUI.PropertyChangeHandler这个类应该被视为一个“受保护”的内部类。
-
Field Summary
Fields Modifier and Type Field 描述 protected booleanhasCustomComponents如果组件包含在消息或按钮中,则在validateComponent中设置为true。protected ComponentinitialFocusComponent在使用selectInitialValue消息时接收焦点的组件。protected JComponentinputComponent如果optionPane.getWantsInput()返回true,则JComponent提供输入。static intMinimumHeightJOptionPane高度为JOptionPane。protected DimensionminimumSize大小JOptionPane。static intMinimumWidthJOptionPane宽度为JOptionPane。protected JOptionPaneoptionPaneJOptionPane接收机正在提供外观和感觉。protected PropertyChangeListenerpropertyChangeListener实例PropertyChangeListener。
-
构造方法摘要
构造方法 Constructor 描述 BasicOptionPaneUI()
-
方法摘要
所有方法 静态方法 接口方法 具体的方法 Modifier and Type 方法 描述 protected voidaddButtonComponents(Container container, Object[] buttons, int initialIndex)创建适当的对象以表示buttons每个对象,并将其添加到container。protected voidaddIcon(Container top)创建并添加一个表示从getIcon返回的图标到top。protected voidaddMessageComponents(Container container, GridBagConstraints cons, Object msg, int maxll, boolean internallyCreated)创建适当的对象以表示msg并将其放入container。protected voidburstStringInto(Container c, String d, int maxll)递归创建新的JLabel实例来表示d。booleancontainsCustomComponents(JOptionPane op)如果在最后一次调用validateComponent消息或按钮包含Component的子类时返回true。protected ActionListenercreateButtonActionListener(int buttonIndex)构造一个新的实例ButtonActionListener。protected ContainercreateButtonArea()创建并返回包含按钮的Container。protected LayoutManagercreateLayoutManager()返回布局管理器。protected ContainercreateMessageArea()消息从installComponents创建一个Container包含消息的正文。protected PropertyChangeListenercreatePropertyChangeListener()返回一个PropertyChangeListener的实例。protected ContainercreateSeparator()返回一个分隔符。static ComponentUIcreateUI(JComponent x)创建一个新的BasicOptionPaneUI实例。protected Object[]getButtons()从JOptionPane返回显示的按钮,接收器提供外观和感觉。protected IcongetIcon()从JOptionPane返回图标,接收器提供外观,或从getDefaultIcon返回的默认图标。protected IcongetIconForType(int messageType)返回用于传入类型的图标。protected intgetInitialValueIndex()将初始索引返回到要选择的按钮中。protected intgetMaxCharactersPerLineCount()返回一行中放置的最大字符数。protected ObjectgetMessage()从JOptionPane返回显示的消息,接收器提供外观和感觉。DimensiongetMinimumOptionPaneSize()返回选项窗格应该是最小的大小。DimensiongetPreferredSize(JComponent c)如果c是JOptionPane的接收方,则返回的首选大小是LayoutManager的JOptionPane和getMinimumOptionPaneSize的首选大小的getMinimumOptionPaneSize。protected booleangetSizeButtonsToSameWidth()返回true,基本的L&F希望所有的按钮具有相同的宽度。protected voidinstallComponents()注册组件。protected voidinstallDefaults()安装默认属性。protected voidinstallKeyboardActions()注册键盘操作。protected voidinstallListeners()注册听众。voidinstallUI(JComponent c)安装接收器作为传递JOptionPane的L&F。protected voidresetInputValue()在选项窗格中设置输入值,接收器根据inputComponent中的值提供外观。voidselectInitialValue(JOptionPane op)如果inputComponent为非空值,那么请求焦点,否则请求关注默认值protected voiduninstallComponents()取消注册组件。protected voiduninstallDefaults()卸载默认属性。protected voiduninstallKeyboardActions()取消注册键盘操作。protected voiduninstallListeners()取消注册听众。voiduninstallUI(JComponent c)从分离窗格中传递的L&F控制器中删除接收者。-
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, paint, update
-
-
-
-
字段详细信息
-
MinimumWidth
public static final int MinimumWidth
JOptionPane宽度为JOptionPane。- 另请参见:
- Constant Field Values
-
MinimumHeight
public static final int MinimumHeight
JOptionPane高度为JOptionPane。- 另请参见:
- Constant Field Values
-
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
如果组件包含在消息或按钮中,则在validateComponent中设置为true。
-
propertyChangeListener
protected PropertyChangeListener propertyChangeListener
实例PropertyChangeListener。
-
-
方法详细信息
-
createUI
public static ComponentUI createUI(JComponent x)
创建一个新的BasicOptionPaneUI实例。- 参数
-
x- 组件 - 结果
-
一个新的
BasicOptionPaneUI实例
-
installUI
public void installUI(JComponent c)
将接收器安装为JOptionPane传递的L&F。- 重写:
-
installUI在ComponentUI - 参数
-
c- 正在安装此UIc的组件 - 另请参见:
-
ComponentUI.uninstallUI(javax.swing.JComponent),JComponent.setUI(javax.swing.plaf.ComponentUI),JComponent.updateUI()
-
uninstallUI
public void uninstallUI(JComponent c)
从分离窗格中传递的L&F控制器中删除接收者。- 重写:
-
uninstallUI类ComponentUI - 参数
-
c- 从中删除此UIc的组件; 这个参数经常被忽略,但如果UI对象是无状态的并且被多个组件共享,则可能会被使用 - 另请参见:
-
ComponentUI.installUI(javax.swing.JComponent),JComponent.updateUI()
-
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的接收器,则返回的首选大小是LayoutManager的JOptionPane和getMinimumOptionPaneSize的首选大小的getMinimumOptionPaneSize。- 重写:
-
getPreferredSize在ComponentUI - 参数
-
c- 要查询其首选大小的组件; 这个参数经常被忽略,但如果UI对象是无状态的并且被多个组件共享,则可能会被使用 - 结果
-
一个
Dimension对象包含给定的组件的首选大小适合外观和感觉 - 另请参见:
-
JComponent.getPreferredSize(),LayoutManager.preferredLayoutSize(java.awt.Container)
-
createMessageArea
protected Container 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,并通过该方法内部创建的(这被用来正确地设定hasCustomComponents仅当internallyCreated是false)。- 参数
-
container- 一个容器 -
cons-实例GridBagConstraints -
msg- 一条消息 -
maxll- 最大长度 -
internallyCreated-true如果组件在内部创建
-
getMessage
protected Object getMessage()
从JOptionPane返回显示的消息,接收器提供外观和感觉。- 结果
- 显示消息
-
addIcon
protected void addIcon(Container top)
创建并添加一个表示从getIcon返回的图标到top。 这是从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有选项设置,他们将被提供,否则,如果optionType为YES_NO_OPTION,yesNoOptions返回,如果类型为YES_NO_CANCEL_OPTIONyesNoCancelOptions返回,否则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为非空值,那么请求焦点,否则请求关注默认值- Specified by:
-
selectInitialValue在OptionPaneUI - 参数
-
op- aJOptionPane
-
containsCustomComponents
public boolean containsCustomComponents(JOptionPane op)
如果在最后一次调用validateComponent消息或按钮包含Component的子类时返回true。- Specified by:
-
containsCustomComponents在OptionPaneUI - 参数
-
op- aJOptionPane - 结果
-
true如果给定的JOptionPane包含用户创建的Components
-
-