- 所有已实现的接口:
-
ImageObserver,MenuContainer,Serializable,Accessible
JOptionPane使弹出标准对话框,提示用户输入值或通知用户某些信息变得容易。有关如何使用JOptionPane的信息,请参阅如何创建对话框,这是The Java Tutorial中的一个部分。
虽然JOptionPane类可能因为拥有大量方法而显得复杂,但几乎所有对这个类的使用都是调用下面静态showXxxDialog方法的一行调用:
| 方法名称 | 描述 |
|---|---|
| showConfirmDialog | 询问确认问题,如是/否/取消。 |
| showInputDialog | 提示输入。 |
| showMessageDialog | 告诉用户发生了什么事情。 |
| showOptionDialog | 上述三者的大一统。 |
showInternalXXX版本,它使用内部框架来容纳对话框(参见JInternalFrame)。还定义了多个便利方法 -- 使用不同参数列表的基本方法的重载版本。
所有对话框都是模态的。每个showXxxDialog方法都会阻塞调用者,直到用户的交互完成。
| 图标 | 消息 |
| 输入值 | |
| 选项按钮 | |
ComponentOrientation属性。
参数:
这些方法的参数遵循一致的模式:
- parentComponent
- 定义将作为此对话框父级的
Component。它以两种方式使用:包含它的Frame用作对话框的Frame父级,并且其屏幕坐标用于放置对话框。通常,对话框放置在组件的正下方。此参数可以为null,在这种情况下,将使用默认的Frame作为父级,并且对话框将在屏幕上居中(取决于外观和感觉)。- message
- 要放置在对话框中的描述性消息。在最常见的用法中,消息只是一个
String或String常量。但是,此参数的类型实际上是Object。其解释取决于其类型:
- Object[]
- 对象数组被解释为垂直堆栈中的一系列消息(每个对象一个)。解释是递归的 -- 数组中的每个对象根据其类型进行解释。
- Component
- 在对话框中显示
Component。- 图标
Icon被包装在JLabel中并显示在对话框中。- 其他
- 通过调用其
toString方法将对象转换为String。结果被包装在JLabel中并显示。- messageType
- 定义消息的样式。外观和感觉管理器可能会根据此值以不同方式布局对话框,并通常会提供默认图标。可能的值有:
ERROR_MESSAGEINFORMATION_MESSAGEWARNING_MESSAGEQUESTION_MESSAGEPLAIN_MESSAGE- optionType
- 定义出现在对话框底部的选项按钮集:
您不限于这组选项按钮。您可以使用options参数提供任何想要的按钮。
DEFAULT_OPTIONYES_NO_OPTIONYES_NO_CANCEL_OPTIONOK_CANCEL_OPTION- options
- 将出现在对话框底部的选项按钮集的更详细描述。options参数的通常值是一个
String数组。但参数类型是一个Objects数组。根据其类型为每个对象创建一个按钮:
- Component
- 将组件直接添加到按钮行。
- 图标
- 使用此作为其标签创建一个
JButton。- 其他
- 通过调用其
toString方法将Object转换为字符串,并将结果用于标记一个JButton。- icon
- 要放置在对话框中的装饰性图标。此参数的默认值由
messageType参数确定。- title
- 对话框的标题。
- initialValue
- 默认选择(输入值)。
当更改选择时,将调用setValue,这将生成一个PropertyChangeEvent。
如果JOptionPane已配置为所有输入setWantsInput,则可以监听绑定属性JOptionPane.INPUT_VALUE_PROPERTY,以确定用户何时输入或选择值。
当showXxxDialog方法之一返回整数时,可能的值为:
YES_OPTIONNO_OPTIONCANCEL_OPTIONOK_OPTIONCLOSED_OPTION
- 显示一个显示消息'alert'的错误对话框:
-
JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE); - 显示一个内部信息对话框,显示消息'information':
-
JOptionPane.showInternalMessageDialog(frame, "information", "information", JOptionPane.INFORMATION_MESSAGE); - 显示一个带有选项是是/否和消息'choose one'的信息面板:
-
JOptionPane.showConfirmDialog(null, "choose one", "choose one", JOptionPane.YES_NO_OPTION); - 显示一个带有选项是/否/取消和消息'please choose one'以及标题信息的内部信息对话框:
-
JOptionPane.showInternalConfirmDialog(frame, "please choose one", "information", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE); - 显示一个带有选项OK、CANCEL、标题'Warning'和消息'Click OK to continue'的警告对话框:
-
Object[] options = { "OK", "CANCEL" }; JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); - 显示一个要求用户输入字符串的对话框:
-
String inputValue = JOptionPane.showInputDialog("Please input a value"); - 显示一个要求用户选择字符串的对话框:
-
Object[] possibleValues = { "First", "Second", "Third" };
Object selectedValue = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.INFORMATION_MESSAGE, null, possibleValues, possibleValues[0]);
要直接创建和使用
JOptionPane,标准模式大致如下:
JOptionPane pane = new JOptionPane(参数);
pane.set.Xxxx(...); // 配置
JDialog dialog = pane.createDialog(parentComponent, title);
dialog.setVisible(true);
Object selectedValue = pane.getValue();
if(selectedValue == null)
return CLOSED_OPTION;
//如果没有选项按钮数组:
if(options == null) {
if(selectedValue instanceof Integer)
return ((Integer)selectedValue).intValue();
return CLOSED_OPTION;
}
//如果有选项按钮数组:
for(int counter = 0, maxCounter = options.length;
counter < maxCounter; counter++) {
if(options[counter].equals(selectedValue))
return counter;
}
return CLOSED_OPTION;
警告: Swing不是线程安全的。有关更多信息,请参阅Swing的线程策略。
警告: 此类的序列化对象将与未来的Swing版本不兼容。当前的序列化支持适用于短期存储或在运行相同Swing版本的应用程序之间的RMI。从1.4开始,已将所有JavaBeans的长期存储支持添加到java.beans包中。请参阅XMLEncoder。
- 自:
- 1.2
- 另请参阅:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class此类为JOptionPane类实现了辅助功能支持。Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int类方法返回值,如果选择了CANCEL。static final int类方法返回值,如果用户在不选择任何内容的情况下关闭窗口,很可能应将其视为CANCEL_OPTION或NO_OPTION。static final int类型表示外观和感觉不应提供任何选项 -- 只使用JOptionPane的选项。static final int用于错误消息。protected Icon用于面板中使用的图标。static final Stringicon的绑定属性名称。static final int用于信息消息。static final StringinitialSelectionValue的绑定属性名称。static final StringinitialValue的绑定属性名称。protected Object在selectionValues中选择的初始值。protected Object应该在options中初始选择的值。static final StringinputValue的绑定属性名称。protected Object用户输入的值。protected Object要显示的消息。static final Stringmessage的绑定属性名称。static final Stringtype的绑定属性名称。protected int消息类型。static final int如果选择“否”,则从类方法返回值。static final int用于showConfirmDialog的类型。static final int如果选择“确定”,则从类方法返回值。static final StringoptionType的绑定属性名称。protected Object[]要显示给用户的选项。static final Stringoption的绑定属性名称。protected int选项类型,可以是DEFAULT_OPTION、YES_NO_OPTION、YES_NO_CANCEL_OPTION或OK_CANCEL_OPTION之一。static final int不使用图标。static final int用于问题。static final StringselectionValues的绑定属性名称。protected Object[]用户可以选择的值数组。static final Object表示用户尚未选择值。protected Object当前选择的值,将是有效选项,或者是UNINITIALIZED_VALUE或null。static final Stringvalue的绑定属性名称。static final StringwantsInput的绑定属性名称。protected boolean如果为true,则将为用户提供UI小部件以获取输入。static final int用于警告消息。static final int用于showConfirmDialog的类型。static final int用于showConfirmDialog的类型。static final int如果选择“是”,则从类方法返回值。Fields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescription创建一个带有测试消息的JOptionPane。JOptionPane(Object message) 创建一个JOptionPane实例,使用普通消息类型和UI提供的默认选项显示消息。JOptionPane(Object message, int messageType) 创建一个JOptionPane实例,显示具有指定消息类型和默认选项的消息,JOptionPane(Object message, int messageType, int optionType) 创建一个JOptionPane实例,显示具有指定消息类型和选项的消息。JOptionPane(Object message, int messageType, int optionType, Icon icon) 创建一个JOptionPane实例,显示具有指定消息类型、选项和图标的消息。JOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options) 创建一个JOptionPane实例,显示具有指定消息类型、图标和选项的消息。JOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options, Object initialValue) 创建一个JOptionPane实例,显示具有指定消息类型、图标和选项的消息,并指定初始选择的选项。 -
Method Summary
Modifier and TypeMethodDescriptioncreateDialog(Component parentComponent, String title) 创建并返回一个在parentComponent的框架中居中显示的this的新JDialog。createDialog(String title) 创建并返回一个具有指定标题的无父级JDialog。createInternalFrame(Component parentComponent, String title) 创建并返回一个JInternalFrame实例。返回与此JOptionPane关联的AccessibleContext。static JDesktopPanegetDesktopPaneForComponent(Component parentComponent) 返回指定组件的桌面面板。static FramegetFrameForComponent(Component parentComponent) 返回指定组件的Frame。getIcon()返回此面板显示的图标。返回作为初始选择显示给用户的输入值。返回初始值。如果wantsInput为true,则返回用户输入的值。int返回消息中放置在一行上的最大字符数。返回此面板显示的消息对象。int返回消息类型。Object[]返回用户可以做出的选择。int返回显示的选项类型。static Frame返回用于在未提供框架的类方法中使用的Frame。Object[]返回输入选择值。getUI()返回实现此组件的L&F的UI对象。返回实现此组件的L&F的UI类的名称。getValue()返回用户选择的值。boolean返回wantsInput属性的值。protected String返回此JOptionPane的字符串表示形式。void请求选择初始值,这将将焦点设置为初始值。void设置要显示的图标。voidsetInitialSelectionValue(Object newValue) 设置作为初始选择显示给用户的输入值。voidsetInitialValue(Object newInitialValue) 设置要启用的初始值 -- 当面板初始显示时具有焦点的Component。voidsetInputValue(Object newValue) 设置用户选择或输入的输入值。voidsetMessage(Object newMessage) 设置选项面板的消息对象。voidsetMessageType(int newType) 设置选项面板的消息类型。voidsetOptions(Object[] newOptions) 设置此面板显示的选项。voidsetOptionType(int newType) 设置要显示的选项。static voidsetRootFrame(Frame newRootFrame) 设置用于在未提供框架的类方法中使用的框架。voidsetSelectionValues(Object[] newValues) 为提供用户选择的列表项的面板设置输入选择值。voidsetUI(OptionPaneUI ui) 设置实现此组件的L&F的UI对象。void设置用户选择的值。voidsetWantsInput(boolean newValue) 设置wantsInput属性。static intshowConfirmDialog(Component parentComponent, Object message) 弹出一个带有选项是、否和取消的对话框;标题为选择一个选项。static intshowConfirmDialog(Component parentComponent, Object message, String title, int optionType) 弹出一个对话框,选择数量由optionType参数确定。static intshowConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) 弹出一个对话框,选择数量由optionType参数确定,其中messageType参数确定要显示的图标。static intshowConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon) 弹出一个带有指定图标的对话框,选择数量由optionType参数确定。static StringshowInputDialog(Component parentComponent, Object message) 显示一个要求用户输入的问题消息对话框,父级为parentComponent。static StringshowInputDialog(Component parentComponent, Object message, Object initialSelectionValue) 显示一个要求用户输入的问题消息对话框,并将其父级设置为parentComponent。static StringshowInputDialog(Component parentComponent, Object message, String title, int messageType) 显示一个要求用户输入的对话框,父级为parentComponent,对话框具有标题title和消息类型messageType。static ObjectshowInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue) 在阻塞对话框中提示用户输入,可以指定初始选择、可能的选择和所有其他选项。static StringshowInputDialog(Object message) 显示一个要求用户输入的问题消息对话框。static StringshowInputDialog(Object message, Object initialSelectionValue) 显示一个要求用户输入的问题消息对话框,并将输入值初始化为initialSelectionValue。static intshowInternalConfirmDialog(Component parentComponent, Object message) 弹出一个内部对话框面板,其中包含选项是、否和取消;标题为选择一个选项。static intshowInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType) 弹出一个内部对话框面板,其中选择数量由optionType参数确定。static intshowInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) 弹出一个内部对话框面板,其中选择数量由optionType参数确定,其中messageType参数确定要显示的图标。static intshowInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon) 弹出一个内部对话框面板,其中选择数量由optionType参数确定,其中指定了带有指定图标的对话框。static StringshowInternalInputDialog(Component parentComponent, Object message) 显示一个内部问题消息对话框,请求用户输入,父级为parentComponent。static StringshowInternalInputDialog(Component parentComponent, Object message, String title, int messageType) 显示一个内部对话框,请求用户输入,父级为parentComponent,对话框具有标题title和消息类型messageType。static ObjectshowInternalInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue) 在阻塞内部对话框中提示用户输入,可以指定初始选择、可能的选择和所有其他选项。static voidshowInternalMessageDialog(Component parentComponent, Object message) 弹出一个内部确认对话框面板。static voidshowInternalMessageDialog(Component parentComponent, Object message, String title, int messageType) 弹出一个内部对话框面板,使用由messageType参数确定的默认图标显示消息。static voidshowInternalMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon) 弹出一个内部对话框面板,显示消息,指定所有参数。static intshowInternalOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) 弹出一个内部对话框面板,其中指定了带有指定图标的对话框,初始选择由initialValue参数确定,选择数量由optionType参数确定。static voidshowMessageDialog(Component parentComponent, Object message) 弹出一个标题为“消息”的信息消息对话框。static voidshowMessageDialog(Component parentComponent, Object message, String title, int messageType) 弹出一个显示消息的对话框,使用由messageType参数确定的默认图标。static voidshowMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon) 弹出一个显示消息的对话框,指定所有参数。static intshowOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) 弹出一个带有指定图标的对话框,初始选择由initialValue参数确定,选择数量由optionType参数确定。voidupdateUI()来自UIManager的通知,L&F已更改。Methods declared in class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods declared in class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods declared in class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
UNINITIALIZED_VALUE
表示用户尚未选择值。 -
DEFAULT_OPTION
public static final int DEFAULT_OPTION表示外观和感觉不应提供任何选项 -- 仅使用JOptionPane的选项。- 参见:
-
YES_NO_OPTION
public static final int YES_NO_OPTION用于showConfirmDialog的类型。- 参见:
-
YES_NO_CANCEL_OPTION
public static final int YES_NO_CANCEL_OPTION用于showConfirmDialog的类型。- 参见:
-
OK_CANCEL_OPTION
public static final int OK_CANCEL_OPTION用于showConfirmDialog的类型。- 参见:
-
YES_OPTION
public static final int YES_OPTION如果选择YES,则从类方法返回的值。- 参见:
-
NO_OPTION
public static final int NO_OPTION如果选择NO,则从类方法返回的值。- 参见:
-
CANCEL_OPTION
public static final int CANCEL_OPTION如果选择CANCEL,则从类方法返回的值。- 参见:
-
OK_OPTION
public static final int OK_OPTION如果选择OK,则从类方法返回的值。- 参见:
-
CLOSED_OPTION
public static final int CLOSED_OPTION如果用户在不选择任何内容的情况下关闭窗口,则从类方法返回的值,很可能应将其视为CANCEL_OPTION或NO_OPTION。- 参见:
-
ERROR_MESSAGE
public static final int ERROR_MESSAGE用于错误消息。- 参见:
-
INFORMATION_MESSAGE
public static final int INFORMATION_MESSAGE用于信息消息。- 参见:
-
WARNING_MESSAGE
public static final int WARNING_MESSAGE用于警告消息。- 参见:
-
QUESTION_MESSAGE
public static final int QUESTION_MESSAGE用于问题。- 参见:
-
PLAIN_MESSAGE
public static final int PLAIN_MESSAGE不使用图标。- 参见:
-
ICON_PROPERTY
icon的绑定属性名称。- 参见:
-
MESSAGE_PROPERTY
message的绑定属性名称。- 参见:
-
VALUE_PROPERTY
value的绑定属性名称。- 参见:
-
OPTIONS_PROPERTY
option的绑定属性名称。- 参见:
-
INITIAL_VALUE_PROPERTY
initialValue的绑定属性名称。- 参见:
-
MESSAGE_TYPE_PROPERTY
type的绑定属性名称。- 参见:
-
OPTION_TYPE_PROPERTY
optionType的绑定属性名称。- 参见:
-
SELECTION_VALUES_PROPERTY
selectionValues的绑定属性名称。- 参见:
-
INITIAL_SELECTION_VALUE_PROPERTY
initialSelectionValue的绑定属性名称。- 参见:
-
INPUT_VALUE_PROPERTY
inputValue的绑定属性名称。- 参见:
-
WANTS_INPUT_PROPERTY
wantsInput的绑定属性名称。- 参见:
-
icon
在窗格中使用的图标。 -
message
要显示的消息。 -
options
要显示给用户的选项。 -
initialValue
应在options中最初选择的值。 -
messageType
protected int messageType消息类型。 -
optionType
protected int optionType选项类型,可以是DEFAULT_OPTION、YES_NO_OPTION、YES_NO_CANCEL_OPTION或OK_CANCEL_OPTION之一。 -
value
当前选择的值,将是有效选项,或者是UNINITIALIZED_VALUE或null。 -
selectionValues
用户可以选择的值的数组。外观和感觉将提供用于选择的UI组件。 -
inputValue
用户输入的值。 -
initialSelectionValue
在selectionValues中最初选择的值。 -
wantsInput
protected boolean wantsInput如果为true,则将为用户提供UI小部件以获取输入。
-
-
Constructor Details
-
JOptionPane
public JOptionPane()创建一个带有测试消息的JOptionPane。 -
JOptionPane
创建一个JOptionPane的实例,使用纯消息消息类型和UI提供的默认选项来显示消息。- 参数:
-
message- 要显示的Object
-
JOptionPane
创建一个JOptionPane的实例,显示具有指定消息类型和默认选项的消息,- 参数:
-
message- 要显示的Object -
messageType- 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE
-
JOptionPane
创建一个JOptionPane的实例,显示具有指定消息类型和选项的消息。- 参数:
-
message- 要显示的Object -
messageType- 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE -
optionType- 要在窗格中显示的选项:DEFAULT_OPTION、YES_NO_OPTION、YES_NO_CANCEL_OPTION、OK_CANCEL_OPTION
-
JOptionPane
创建一个JOptionPane的实例,显示具有指定消息类型、选项和图标的消息。- 参数:
-
message- 要显示的Object -
messageType- 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE -
optionType- 要在窗格中显示的选项:DEFAULT_OPTION、YES_NO_OPTION、YES_NO_CANCEL_OPTION、OK_CANCEL_OPTION -
icon- 要显示的Icon图像
-
JOptionPane
创建一个JOptionPane的实例,显示具有指定消息类型、图标和选项的消息。初始情况下,没有选中任何选项。选项对象应包含
Component的实例(直接添加)或Strings(包装在JButton中)。如果提供Component,必须确保当单击Component时,它会在创建的JOptionPane中发送setValue消息。- 参数:
-
message- 要显示的Object -
messageType- 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE -
optionType- 要在窗格中显示的选项:DEFAULT_OPTION、YES_NO_OPTION、YES_NO_CANCEL_OPTION、OK_CANCEL_OPTION -
icon- 要显示的Icon图像 -
options- 用户可以选择的选项
-
JOptionPane
public JOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options, Object initialValue) 创建一个JOptionPane的实例,显示具有指定消息类型、图标和选项的消息,并指定最初选择的选项。- 参数:
-
message- 要显示的Object -
messageType- 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE -
optionType- 在窗格中显示的选项:DEFAULT_OPTION、YES_NO_OPTION、YES_NO_CANCEL_OPTION、OK_CANCEL_OPTION -
icon- 要显示的图标 -
options- 用户可以选择的选项 -
initialValue- 最初选择的选项;如果为null,则最初不会选择任何选项;仅在使用options时有意义
-
-
Method Details
-
showInputDialog
显示一个要求用户输入的问题消息对话框。对话框使用默认框架,通常居中显示在屏幕上。- 参数:
-
message- 要显示的Object - 返回:
- 用户的输入
- 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
showInputDialog
显示一个要求用户输入的问题消息对话框,并将输入值初始化为initialSelectionValue。对话框使用默认框架,通常居中显示在屏幕上。- 参数:
-
message- 要显示的Object -
initialSelectionValue- 用于初始化输入字段的值 - 返回:
- 用户的输入
- 自版本:
- 1.4
-
showInputDialog
public static String showInputDialog(Component parentComponent, Object message) throws HeadlessException 显示一个要求用户输入的问题消息对话框,其父级为parentComponent。对话框显示在Component的框架顶部,并通常位于Component的下方。- 参数:
-
parentComponent- 对话框的父级Component -
message- 要显示的Object - 返回:
- 用户的输入
- 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
showInputDialog
public static String showInputDialog(Component parentComponent, Object message, Object initialSelectionValue) 显示一个要求用户输入的问题消息对话框,并将其父级设为parentComponent。输入值将初始化为initialSelectionValue。对话框显示在Component的框架顶部,并通常位于Component的下方。- 参数:
-
parentComponent- 对话框的父级Component -
message- 要显示的Object -
initialSelectionValue- 用于初始化输入字段的值 - 返回:
- 用户的输入
- 自版本:
- 1.4
-
showInputDialog
public static String showInputDialog(Component parentComponent, Object message, String title, int messageType) throws HeadlessException 显示一个对话框,请求用户输入,并将其父级设为parentComponent,对话框具有标题title和消息类型messageType。- 参数:
-
parentComponent- 对话框的父级Component -
message- 要显示的Object -
title- 要显示在对话框标题栏中的String -
messageType- 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE - 返回:
- 用户的输入
- 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
showInputDialog
public static Object showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue) throws HeadlessException 在一个阻塞对话框中提示用户输入,可以指定初始选择、可能的选择和所有其他选项。用户可以从selectionValues中选择,其中null表示用户可以输入任何他们希望的内容,通常通过JTextField。initialSelectionValue是提示用户的初始值。UI可以决定最佳表示selectionValues的方式,但通常会使用JComboBox、JList或JTextField。- 参数:
-
parentComponent- 对话框的父级Component -
message- 要显示的Object -
title- 要显示在对话框标题栏中的String -
messageType- 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE -
icon- 要显示的Icon图标 -
selectionValues- 一个包含可能选择的Object数组 -
initialSelectionValue- 用于初始化输入字段的值 - 返回:
-
用户的输入,或
null表示用户取消了输入 - 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
showMessageDialog
public static void showMessageDialog(Component parentComponent, Object message) throws HeadlessException 弹出一个标题为"Message"的信息消息对话框。- 参数:
-
parentComponent- 确定显示对话框的Frame;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要显示的Object - 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
showMessageDialog
public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType) throws HeadlessException 弹出一个显示消息的对话框,使用由messageType参数确定的默认图标。- 参数:
-
parentComponent- 确定显示对话框的Frame;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要显示的Object -
title- 对话框的标题字符串 -
messageType- 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE - 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
showMessageDialog
public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon) throws HeadlessException 弹出一个显示消息的对话框,指定所有参数。- 参数:
-
parentComponent- 确定显示对话框的Frame;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要显示的Object -
title- 对话框的标题字符串 -
messageType- 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE -
icon- 在对话框中显示的帮助用户识别消息类型的图标 - 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
showConfirmDialog
public static int showConfirmDialog(Component parentComponent, Object message) throws HeadlessException 弹出一个带有选项Yes、No和Cancel的对话框;标题为选择一个选项。- 参数:
-
parentComponent- 确定显示对话框的Frame;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要显示的Object - 返回:
- 一个整数,指示用户选择的选项
- 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
showConfirmDialog
public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType) throws HeadlessException 弹出一个对话框,选项数量由optionType参数确定。- 参数:
-
parentComponent- 确定对话框显示在哪个Frame中;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要显示的Object -
title- 对话框的标题字符串 -
optionType- 一个整数,指定对话框上可用的选项:YES_NO_OPTION、YES_NO_CANCEL_OPTION或OK_CANCEL_OPTION - 返回:
- 表示用户选择的选项的整数
- 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
showConfirmDialog
public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) throws HeadlessException 弹出一个对话框,选项的数量由optionType参数确定,messageType参数确定要显示的图标。messageType参数主要用于从外观和感觉中提供默认图标。- 参数:
-
parentComponent- 确定对话框显示在哪个Frame中;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要显示的Object -
title- 对话框的标题字符串 -
optionType- 一个整数,指定对话框上可用的选项:YES_NO_OPTION、YES_NO_CANCEL_OPTION或OK_CANCEL_OPTION -
messageType- 一个整数,指定此消息的类型;主要用于从可插拔的外观和感觉中确定图标:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE - 返回:
- 表示用户选择的选项的整数
- 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
showConfirmDialog
public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon) throws HeadlessException 弹出一个带有指定图标的对话框,选项的数量由optionType参数确定。messageType参数主要用于从外观和感觉中提供默认图标。- 参数:
-
parentComponent- 确定对话框显示在哪个Frame中;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要显示的Object -
title- 对话框的标题字符串 -
optionType- 一个整数,指定对话框上可用的选项:YES_NO_OPTION、YES_NO_CANCEL_OPTION或OK_CANCEL_OPTION -
messageType- 一个整数,指定此消息的类型,主要用于从可插拔的外观和感觉中确定图标:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE -
icon- 在对话框中显示的图标 - 返回:
- 表示用户选择的选项的整数
- 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
showOptionDialog
public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException 弹出一个带有指定图标的对话框,初始选择由initialValue参数确定,选项的数量由optionType参数确定。如果
optionType为YES_NO_OPTION或YES_NO_CANCEL_OPTION,并且options参数为null,则选项由外观和感觉提供。messageType参数主要用于从外观和感觉中提供默认图标。- 参数:
-
parentComponent- 确定对话框显示在哪个Frame中;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要显示的Object -
title- 对话框的标题字符串 -
optionType- 一个整数,指定对话框上可用的选项:DEFAULT_OPTION、YES_NO_OPTION、YES_NO_CANCEL_OPTION或OK_CANCEL_OPTION -
messageType- 一个整数,指定此消息的类型,主要用于从可插拔的外观和感觉中确定图标:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE -
icon- 在对话框中显示的图标 -
options- 一个对象数组,指示用户可以做出的可能选择;如果对象是组件,则会正确呈现;非String对象使用其toString方法呈现;如果此参数为null,则选项由外观和感觉确定 -
initialValue- 表示对话框的默认选择的对象;仅在使用options时有意义;可以为null - 返回:
-
表示用户选择的选项的整数,如果用户关闭对话框,则为
CLOSED_OPTION - 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
createDialog
创建并返回一个新的JDialog,将this居中显示在parentComponent的Frame中。title是返回对话框的标题。 返回的JDialog将不可由用户调整大小,但程序可以在JDialog实例上调用setResizable来更改此属性。 返回的JDialog将被设置,一旦关闭,或用户单击其中一个按钮,选项面板的值属性将相应设置并关闭对话框。 每次对话框可见时,它将重置选项面板的值属性为JOptionPane.UNINITIALIZED_VALUE,以确保用户的后续操作正确关闭对话框。- 参数:
-
parentComponent- 确定对话框显示在哪个Frame中;如果parentComponent没有Frame,则使用默认的Frame -
title- 对话框的标题字符串 - 返回:
-
包含此实例的新
JDialog - 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
createDialog
创建并返回一个新的无父级的JDialog,具有指定的标题。 返回的JDialog将不可由用户调整大小,但程序可以在JDialog实例上调用setResizable来更改此属性。 返回的JDialog将被设置,一旦关闭,或用户单击其中一个按钮,选项面板的值属性将相应设置并关闭对话框。 每次对话框可见时,它将重置选项面板的值属性为JOptionPane.UNINITIALIZED_VALUE,以确保用户的后续操作正确关闭对话框。- 参数:
-
title- 对话框的标题字符串 - 返回:
-
包含此实例的新
JDialog - 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 自:
- 1.6
- 参见:
-
showInternalMessageDialog
弹出一个内部确认对话框面板。 对话框是一个标题为"Message"的信息消息对话框。- 参数:
-
parentComponent- 确定对话框显示在哪个Frame中;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要显示的对象
-
showInternalMessageDialog
public static void showInternalMessageDialog(Component parentComponent, Object message, String title, int messageType) 弹出一个内部对话框面板,使用messageType参数确定的默认图标显示消息。- 参数:
-
parentComponent- 确定对话框显示在哪个Frame中;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要显示的Object -
title- 对话框的标题字符串 -
messageType- 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE
-
showInternalMessageDialog
public static void showInternalMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon) 弹出一个内部对话框面板显示消息,指定所有参数。- 参数:
-
parentComponent- 确定对话框显示在哪个Frame中;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要显示的Object -
title- 对话框的标题字符串 -
messageType- 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE -
icon- 在对话框中显示的图标,帮助用户识别显示的消息类型
-
showInternalConfirmDialog
弹出一个内部对话框面板,带有选项是、否和取消;标题为选择一个选项。- 参数:
-
parentComponent- 确定对话框显示在哪个Frame中;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要显示的Object - 返回:
- 表示用户选择的选项的整数
-
showInternalConfirmDialog
public static int showInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType) 弹出一个内部对话框面板,其中的选择数量由optionType参数确定。- 参数:
-
parentComponent- 确定对话框显示在哪个Frame中;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要在对话框中显示的对象;Component对象呈现为Component;String对象呈现为字符串;其他对象使用toString方法转换为String -
title- 对话框的标题字符串 -
optionType- 指定对话框上可用选项的整数:YES_NO_OPTION或YES_NO_CANCEL_OPTION - 返回:
- 表示用户选择的选项的整数
-
showInternalConfirmDialog
public static int showInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) 弹出一个内部对话框面板,其中的选择数量由optionType参数确定,messageType参数确定要显示的图标。messageType参数主要用于从外观中提供默认图标。- 参数:
-
parentComponent- 确定对话框显示在哪个Frame中;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要在对话框中显示的对象;Component对象呈现为Component;String对象呈现为字符串;其他对象使用toString方法转换为String -
title- 对话框的标题字符串 -
optionType- 指定对话框上可用选项的整数:YES_NO_OPTION或YES_NO_CANCEL_OPTION -
messageType- 指定消息类型的整数,主要用于从外观中确定图标:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE - 返回:
- 表示用户选择的选项的整数
-
showInternalConfirmDialog
public static int showInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon) 弹出一个内部对话框面板,带有指定的图标,其中的选择数量由optionType参数确定。messageType参数主要用于从外观中提供默认图标。- 参数:
-
parentComponent- 确定对话框显示在哪个Frame中;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要在对话框中显示的对象;Component对象呈现为Component;String对象呈现为字符串;其他对象使用toString方法转换为String -
title- 对话框的标题字符串 -
optionType- 指定对话框上可用选项的整数:YES_NO_OPTION或YES_NO_CANCEL_OPTION -
messageType- 指定消息类型的整数,主要用于从外观中确定图标:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE -
icon- 在对话框中显示的图标 - 返回:
- 表示用户选择的选项的整数
-
showInternalOptionDialog
public static int showInternalOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) 弹出一个内部对话框面板,带有指定的图标,初始选择由initialValue参数确定,选择数量由optionType参数确定。如果
optionType为YES_NO_OPTION或YES_NO_CANCEL_OPTION,并且options参数为null,则选项由外观提供。messageType参数主要用于从外观中提供默认图标。- 参数:
-
parentComponent- 确定对话框显示在哪个Frame中;如果为null,或者parentComponent没有Frame,则使用默认的Frame -
message- 要在对话框中显示的对象;Component对象呈现为Component;String对象呈现为字符串。其他对象使用toString方法转换为String -
title- 对话框的标题字符串 -
optionType- 指定对话框上可用选项的整数:YES_NO_OPTION或YES_NO_CANCEL_OPTION -
messageType- 指定消息类型的整数;主要用于从外观中确定图标:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE -
icon- 在对话框中显示的图标 -
options- 一个对象数组,指示用户可以进行的可能选择;如果对象是组件,则会正确呈现;非String对象使用其toString方法呈现;如果此参数为null,则选项由外观确定 -
initialValue- 表示对话框的默认选择的对象;仅在使用options时有意义;可以为null - 返回:
-
表示用户选择的选项的整数,如果用户关闭对话框,则为
CLOSED_OPTION
-
showInternalInputDialog
显示一个内部问题消息对话框,请求用户在parentComponent下输入。对话框显示在Component的框架中,并通常位于Component下方。- 参数:
-
parentComponent- 对话框的父Component -
message- 要显示的Object - 返回:
- 用户的输入
-
showInternalInputDialog
public static String showInternalInputDialog(Component parentComponent, Object message, String title, int messageType) 显示一个内部对话框,请求用户在parentComponent下输入,对话框具有标题title和消息类型messageType。- 参数:
-
parentComponent- 对话框的父Component -
message- 要显示的Object -
title- 要显示在对话框标题栏中的String -
messageType- 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE - 返回:
- 用户的输入
-
showInternalInputDialog
public static Object showInternalInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue) 在一个阻塞的内部对话框中提示用户输入,可以指定初始选择、可能的选择和所有其他选项。用户可以从selectionValues中选择,其中null表示用户可以输入任何他们希望的内容,通常通过JTextField。initialSelectionValue是用于提示用户的初始值。如何最好地表示selectionValues取决于UI,但通常会使用JComboBox、JList或JTextField。- 参数:
-
parentComponent- 对话框的父Component -
message- 要显示的Object -
title- 要显示在对话框标题栏中的String -
messageType- 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE或PLAIN_MESSAGE -
icon- 要显示的Icon图像 -
selectionValues- 一个包含可能选择的Objects数组 -
initialSelectionValue- 用于初始化输入字段的值 - 返回:
-
用户的输入,或
null表示用户取消了输入
-
createInternalFrame
创建并返回一个JInternalFrame实例。内部框架使用指定的标题创建,并包装JOptionPane。返回的JInternalFrame添加到parentComponent的JDesktopPane祖先中,如果parentComponent的祖先之一不是JDesktopPane,或者如果parentComponent没有父级,则抛出RuntimeException。- 参数:
-
parentComponent- 内部框架的父Component -
title- 在框架标题栏中显示的String - 返回:
-
包含
JOptionPane的JInternalFrame - 抛出:
-
RuntimeException- 如果parentComponent没有有效的父级
-
getFrameForComponent
返回指定组件的Frame。- 参数:
-
parentComponent- 要检查Frame的Component - 返回:
-
包含组件的
Frame,如果组件为null或没有有效的Frame父级,则返回getRootFrame - 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
getDesktopPaneForComponent
返回指定组件的桌面窗格。- 参数:
-
parentComponent- 要检查桌面的Component - 返回:
-
包含组件的
JDesktopPane,如果组件为null或没有祖先是JInternalFrame的,则返回null
-
setRootFrame
设置用于在未提供框架的类方法中使用的框架。注意: 建议您提供有效的父级,而不是使用此方法。
- 参数:
-
newRootFrame- 要使用的默认Frame
-
getRootFrame
返回用于在未提供框架的类方法中使用的Frame。- 返回:
-
要使用的默认
Frame - 抛出:
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 参见:
-
setUI
@BeanProperty(hidden=true, description="The UI object that implements the optionpane\'s LookAndFeel") public void setUI(OptionPaneUI ui) 设置实现此组件的L&F的UI对象。- 参数:
-
ui-OptionPaneUIL&F对象 - 参见:
-
getUI
返回实现此组件的L&F的UI对象。- 覆盖:
-
getUI在类JComponent中 - 返回:
-
OptionPaneUI对象
-
updateUI
public void updateUI()来自UIManager的通知,L&F已更改。使用最新版本从UIManager替换当前UI对象。- 覆盖:
-
updateUI在类JComponent中 - 参见:
-
getUIClassID
返回实现此组件的L&F的UI类的名称。- 覆盖:
-
getUIClassID在类JComponent中 - 返回:
- 字符串"OptionPaneUI"
- 参见:
-
setMessage
@BeanProperty(preferred=true, description="The optionpane\'s message object.") public void setMessage(Object newMessage) 设置要显示的选项面板的消息对象。- 参数:
-
newMessage- 要显示的Object - 参见:
-
getMessage
返回此面板显示的消息对象。- 返回:
-
显示的
Object - 参见:
-
setIcon
@BeanProperty(preferred=true, description="The option pane\'s type icon.") public void setIcon(Icon newIcon) 设置要显示的图标。如果非null,外观不提供图标。- 参数:
-
newIcon- 要显示的Icon - 参见:
-
getIcon
返回此面板显示的图标。- 返回:
-
显示的
Icon - 参见:
-
setValue
@BeanProperty(preferred=true, description="The option pane\'s value object.") public void setValue(Object newValue) 设置用户选择的值。- 参数:
-
newValue- 选择的值 - 参见:
-
getValue
返回用户选择的值。UNINITIALIZED_VALUE表示用户尚未做出选择,null表示用户关闭窗口而没有选择任何内容。否则,返回值将是此对象中定义的选项之一。- 返回:
-
用户选择的
Object,如果用户尚未做出选择,则为UNINITIALIZED_VALUE,如果用户关闭窗口而没有做出选择,则为null - 参见:
-
setOptions
@BeanProperty(description="The option pane\'s options objects.") public void setOptions(Object[] newOptions) 设置此面板显示的选项。如果newOptions中的元素是Component,则直接添加到面板中,否则为元素创建按钮。- 参数:
-
newOptions- 创建用户可以单击的按钮或要添加到面板的任意Components的Objects数组 - 参见:
-
getOptions
返回用户可以做出的选择。- 返回:
-
给出用户选择的
Objects数组 - 参见:
-
setInitialValue
@BeanProperty(preferred=true, description="The option pane\'s initial value object.") public void setInitialValue(Object newInitialValue) 设置要启用的初始值 -- 当面板初始显示时具有焦点的Component。- 参数:
-
newInitialValue- 获取初始键盘焦点的Object - 参见:
-
getInitialValue
返回初始值。- 返回:
-
获取初始键盘焦点的
Object - 参见:
-
setMessageType
@BeanProperty(preferred=true, description="The option pane\'s message type.") public void setMessageType(int newType) 设置选项面板的消息类型。消息类型由外观确定要显示的图标(如果未提供),以及可能如何布局parentComponent。- 参数:
-
newType- 指定要显示的消息类型的整数:ERROR_MESSAGE,INFORMATION_MESSAGE,WARNING_MESSAGE,QUESTION_MESSAGE或PLAIN_MESSAGE - 抛出:
-
RuntimeException- 如果newType不是上述合法值之一 - 参见:
-
getMessageType
public int getMessageType()返回消息类型。- 返回:
- 指定消息类型的整数
- 参见:
-
setOptionType
@BeanProperty(preferred=true, description="The option pane\'s option type.") public void setOptionType(int newType) 设置要显示的选项。选项类型由外观确定要显示哪些按钮(除非提供了选项)。- 参数:
-
newType- 指定L&F要显示的选项的整数:DEFAULT_OPTION,YES_NO_OPTION,YES_NO_CANCEL_OPTION或OK_CANCEL_OPTION - 抛出:
-
RuntimeException- 如果newType不是上述合法值之一 - 参见:
-
getOptionType
public int getOptionType()返回显示的选项类型。- 返回:
- 指定用户可选择选项的整数
- 参见:
-
setSelectionValues
@BeanProperty(description="The option pane\'s selection values.") public void setSelectionValues(Object[] newValues) 设置用户可以选择的项目列表的输入选择值。 (UI提供了一个小部件,用于选择其中一个值。)null值意味着用户可以输入他们想要的任何内容,通常是通过JTextField。将
wantsInput设置为true。使用setInitialSelectionValue指定最初选择的值。在启用窗格后,inputValue设置为用户选择的值。- 参数:
-
newValues- 要显示给用户的Objects数组(通常在列表或组合框中),用户可以从中进行选择 - 参见:
-
getSelectionValues
返回输入选择的值。- 返回:
-
用户可以选择的
Objects数组 - 参见:
-
setInitialSelectionValue
@BeanProperty(description="The option pane\'s initial selection value object.") public void setInitialSelectionValue(Object newValue) 设置最初显示给用户选择的输入值。仅在wantsInput为true时使用。- 参数:
-
newValue- 最初选择的值 - 参见:
-
getInitialSelectionValue
返回最初显示给用户选择的输入值。- 返回:
- 最初选择的值
- 参见:
-
setInputValue
@BeanProperty(preferred=true, description="The option pane\'s input value object.") public void setInputValue(Object newValue) 设置用户选择或输入的输入值。仅在wantsInput为true时使用。请注意,此方法由选项窗格在内部调用(响应用户操作),通常不应由客户端程序调用。要设置最初显示给用户选择的输入值,请使用setInitialSelectionValue。- 参数:
-
newValue- 用于设置用户指定的值(通常在文本字段中)的Object - 参见:
-
getInputValue
返回用户输入的值,如果wantsInput为true。- 返回:
-
用户指定的
Object,如果是对象之一,或者如果是键入到字段中的值,则为String - 参见:
-
getMaxCharactersPerLineCount
返回消息中放置在一行上的最大字符数。默认情况下返回Integer.MAX_VALUE。可以通过在子类中覆盖此方法来更改该值。- 返回:
- 一行上的最大字符数的整数
-
setWantsInput
@BeanProperty(preferred=true, description="Flag which allows the user to input a value.") public void setWantsInput(boolean newValue) 设置wantsInput属性。如果newValue为true,则提供一个输入组件(例如文本字段或组合框),其父级为parentComponent,以允许用户输入值。如果getSelectionValues返回一个非null数组,则输入值是该数组中的一个对象。否则,输入值为用户输入的任何内容。这是一个绑定属性。
- 参数:
-
newValue- 如果为true,则提供一个父级为parentComponent的输入组件,以允许用户输入值。 - 参见:
-
getWantsInput
public boolean getWantsInput()返回wantsInput属性的值。- 返回:
- 如果将提供一个输入组件,则为true
- 参见:
-
selectInitialValue
public void selectInitialValue()请求选择初始值,这将将焦点设置为初始值。此方法应在包含选项窗格的窗口可见后调用。 -
paramString
返回此JOptionPane的字符串表示形式。此方法仅用于调试目的,返回的字符串的内容和格式可能因实现而异。返回的字符串可能为空,但不能为null。- 覆盖:
-
paramString在类JComponent - 返回:
-
此
JOptionPane的字符串表示形式
-
getAccessibleContext
@BeanProperty(bound=false, expert=true, description="The AccessibleContext associated with this option pane") public AccessibleContext getAccessibleContext()返回与此JOptionPane关联的AccessibleContext。对于选项窗格,AccessibleContext采用AccessibleJOptionPane的形式。如果需要,将创建一个新的AccessibleJOptionPane实例。- 指定者:
-
getAccessibleContext在接口Accessible - 覆盖:
-
getAccessibleContext在类Component - 返回:
- 作为此AccessibleJOptionPane的AccessibleContext的AccessibleJOptionPane
-