- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JOptionPane
-
- 实现的所有接口
-
ImageObserver,MenuContainer,Serializable,Accessible
@JavaBean(defaultProperty="UI", description="A component which implements standard dialog box controls.") public class JOptionPane extends JComponent implements Accessible
JOptionPane可以轻松弹出一个标准对话框,提示用户输入值或通知他们某些内容。 有关使用JOptionPane信息,请参阅“Java教程”中的 How to Make Dialogs部分。虽然
Common JOptionPane method names and their descriptions Method Name Description showConfirmDialog Asks a confirming question, like yes/no/cancel. showInputDialog Prompt for some input. showMessageDialog Tell the user about something that has happened. showOptionDialog The Grand Unification of the above three.JOptionPane类可能因为大量方法而显得复杂,但此类的几乎所有用法都是对以下所示的静态showXxxDialog方法之一的单行调用:
这些方法中的每一种showInternalXXX一个showInternalXXX风格,它使用内部框架来保存对话框(参见JInternalFrame)。 还定义了多种便捷方法 - 使用不同参数列表的基本方法的重载版本。所有对话都是模态的。 每个
Common dialog icon message input value option buttonsshowXxxDialog方法都会阻止调用方,直到用户的交互完成。
其中一个对话框的基本外观与上图类似,尽管各种外观最终都是最终结果的原因。 特别是,外观将调整布局以适应选项窗格的ComponentOrientation属性。
参数:
这些方法的参数遵循一致的模式:- parentComponent
-
Defines the
Componentthat is to be the parent of this dialog box. It is used in two ways: theFramethat contains it is used as theFrameparent for the dialog box, and its screen coordinates are used in the placement of the dialog box. In general, the dialog box is placed just below the component. This parameter may benull, in which case a defaultFrameis used as the parent, and the dialog will be centered on the screen (depending on the L&F). - message
-
A descriptive message to be placed in the dialog box. In the most common usage, message is just a
StringorStringconstant. However, the type of this parameter is actuallyObject. Its interpretation depends on its type:- Object[]
- An array of objects is interpreted as a series of messages (one per object) arranged in a vertical stack. The interpretation is recursive -- each object in the array is interpreted according to its type.
- Component
-
The
Componentis displayed in the dialog. - Icon
-
The
Iconis wrapped in aJLabeland displayed in the dialog. - others
-
The object is converted to a
Stringby calling itstoStringmethod. The result is wrapped in aJLabeland displayed.
- messageType
-
Defines the style of the message. The Look and Feel manager may lay out the dialog differently depending on this value, and will often provide a default icon. The possible values are:
ERROR_MESSAGEINFORMATION_MESSAGEWARNING_MESSAGEQUESTION_MESSAGEPLAIN_MESSAGE
- optionType
-
Defines the set of option buttons that appear at the bottom of the dialog box:
DEFAULT_OPTIONYES_NO_OPTIONYES_NO_CANCEL_OPTIONOK_CANCEL_OPTION
- options
-
A more detailed description of the set of option buttons that will appear at the bottom of the dialog box. The usual value for the options parameter is an array of
Strings. But the parameter type is an array ofObjects. A button is created for each object depending on its type:- Component
- The component is added to the button row directly.
- Icon
-
A
JButtonis created with this as its label. - other
-
The
Objectis converted to a string using itstoStringmethod and the result is used to label aJButton.
- icon
-
A decorative icon to be placed in the dialog box. A default value for this is determined by the
messageTypeparameter. - title
- The title for the dialog box.
- initialValue
- The default selection (input value).
更改选择后,将调用
setValue,生成PropertyChangeEvent。如果
JOptionPane已配置为所有输入setWantsInput,则还可以侦听绑定属性JOptionPane.INPUT_VALUE_PROPERTY,以确定用户何时输入或选择了值。当其中一个
showXxxDialog方法返回一个整数时,可能的值为:-
YES_OPTION -
NO_OPTION -
CANCEL_OPTION -
OK_OPTION -
CLOSED_OPTION
- 显示错误对话框,显示消息“alert”:
-
JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE); - 显示内容信息对话框,其中包含“信息”消息:
-
JOptionPane.showInternalMessageDialog(frame, "information", "information", JOptionPane.INFORMATION_MESSAGE); - 显示一个信息面板,其中包含选项yes / no和消息'choose one':
-
JOptionPane.showConfirmDialog(null, "choose one", "choose one", JOptionPane.YES_NO_OPTION); - 显示内部信息对话框,其中包含选项yes / no / cancel和消息'please choose one'和标题信息:
-
JOptionPane.showInternalConfirmDialog(frame, "please choose one", "information", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE); - 显示一个警告对话框,其中包含选项OK,CANCEL,标题'Warning'和消息'单击OK继续':
-
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(arguments); pane.set.Xxxx(...); // Configure JDialog dialog = pane.createDialog(parentComponent, title); dialog.show(); Object selectedValue = pane.getValue(); if(selectedValue == null) return CLOSED_OPTION; //If there is not an array of option buttons: if(options == null) { if(selectedValue instanceof Integer) return ((Integer)selectedValue).intValue(); return CLOSED_OPTION; } //If there is an array of option buttons: for(int counter = 0, maxCounter = options.length; counter < maxCounter; counter++) { if(options[counter].equals(selectedValue)) return counter; } return CLOSED_OPTION;警告: Swing不是线程安全的。 有关更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与以后的Swing版本不兼容。 当前的序列化支持适用于运行相同版本Swing的应用程序之间的短期存储或RMI。 从1.4开始,
java.beans软件包中添加了对所有JavaBeansjava.beans长期存储的支持。 请参阅XMLEncoder。- 从以下版本开始:
- 1.2
- 另请参见:
-
JInternalFrame, Serialized Form
-
-
嵌套类汇总
嵌套类 变量和类型 类 描述 protected classJOptionPane.AccessibleJOptionPane此类实现JOptionPane类的可访问性支持。-
嵌套类/接口声明在类 javax.swing.JComponent
JComponent.AccessibleJComponent
-
嵌套类/接口声明在类 java.awt.Container
Container.AccessibleAWTContainer
-
-
字段汇总
字段 变量和类型 字段 描述 static intCANCEL_OPTION如果选择CANCEL,则从类方法返回值。static intCLOSED_OPTION如果用户在没有选择任何内容的情况下关闭窗口,则从类方法返回值,这可能会被视为CANCEL_OPTION或NO_OPTION。static intDEFAULT_OPTION类型含义外观和感觉不应提供任何选项 - 仅使用JOptionPane的选项。static intERROR_MESSAGE用于错误消息。protected Iconicon窗格中使用的图标。static StringICON_PROPERTY绑定属性名称为icon。static intINFORMATION_MESSAGE用于信息消息。static StringINITIAL_SELECTION_VALUE_PROPERTY绑定属性名称为initialSelectionValue。static StringINITIAL_VALUE_PROPERTY绑定属性名称为initialValue。protected ObjectinitialSelectionValue要在selectionValues选择的初始值。protected ObjectinitialValue应在options初始选择的options。static StringINPUT_VALUE_PROPERTY绑定属性名称为inputValue。protected ObjectinputValue用户输入的值。protected Objectmessage要显示的消息。static StringMESSAGE_PROPERTY绑定属性名称为message。static StringMESSAGE_TYPE_PROPERTY绑定属性名称为type。protected intmessageType消息类型。static intNO_OPTION如果选择NO,则从类方法返回值。static intOK_CANCEL_OPTION用于showConfirmDialog类型。static intOK_OPTION如果选择OK,则返回值表单类方法。static StringOPTION_TYPE_PROPERTY绑定属性名称为optionType。protected Object[]options显示给用户的选项。static StringOPTIONS_PROPERTY绑定属性名称为option。protected intoptionType选项类型的一个DEFAULT_OPTION,YES_NO_OPTION,YES_NO_CANCEL_OPTION或OK_CANCEL_OPTION。static intPLAIN_MESSAGE没有使用图标。static intQUESTION_MESSAGE用于提问。static StringSELECTION_VALUES_PROPERTY绑定属性名称为selectionValues。protected Object[]selectionValues用户可以选择的值数组。static ObjectUNINITIALIZED_VALUE表示用户尚未选择值。protected Objectvalue当前选择的值,将是有效选项,或UNINITIALIZED_VALUE或null。static StringVALUE_PROPERTY绑定属性名称为value。static StringWANTS_INPUT_PROPERTY绑定属性名称为wantsInput。protected booleanwantsInput如果为true,则将向用户提供UI小部件以获取输入。static intWARNING_MESSAGE用于警告消息。static intYES_NO_CANCEL_OPTION用于showConfirmDialog类型。static intYES_NO_OPTION用于showConfirmDialog类型。static intYES_OPTION如果选择YES,则从类方法返回值。-
声明的属性在类 javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
声明的属性在类 java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
构造方法摘要
构造方法 构造器 描述 JOptionPane()使用测试消息创建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的实例以显示具有指定消息类型,图标和选项的消息,并指定最初选择的选项。
-
方法摘要
所有方法 静态方法 实例方法 具体的方法 变量和类型 方法 描述 JDialogcreateDialog(Component parentComponent, String title)创建并返回JDialog包装this中心位于parentComponent中的parentComponent。JDialogcreateDialog(String title)创建并返回具有指定标题的新的无父对象JDialog。JInternalFramecreateInternalFrame(Component parentComponent, String title)创建并返回JInternalFrame的实例。AccessibleContextgetAccessibleContext()返回与此JOptionPane关联的AccessibleContext。static JDesktopPanegetDesktopPaneForComponent(Component parentComponent)返回指定组件的桌面窗格。static FramegetFrameForComponent(Component parentComponent)返回指定的组件Frame。IcongetIcon()返回此窗格显示的图标。ObjectgetInitialSelectionValue()返回最初选择给用户显示的输入值。ObjectgetInitialValue()返回初始值。ObjectgetInputValue()如果wantsInput为true,则返回用户输入的值。intgetMaxCharactersPerLineCount()返回消息中一行上的最大字符数。ObjectgetMessage()返回此窗格显示的消息对象。intgetMessageType()返回消息类型。Object[]getOptions()返回用户可以做出的选择。intgetOptionType()返回显示的选项类型。static FramegetRootFrame()返回Frame以用于未提供框架的类方法。Object[]getSelectionValues()返回输入选择值。OptionPaneUIgetUI()返回实现此组件的L&F的UI对象。StringgetUIClassID()返回实现此组件的L&F的UI类的名称。ObjectgetValue()返回用户选择的值。booleangetWantsInput()返回wantsInput属性的值。protected StringparamString()返回此JOptionPane的字符串表示JOptionPane。voidselectInitialValue()请求选择初始值,将焦点设置为初始值。voidsetIcon(Icon newIcon)设置要显示的图标。voidsetInitialSelectionValue(Object newValue)将最初显示为选定的输入值设置为用户。voidsetInitialValue(Object newInitialValue)设置要启用的初始值 - 最初显示窗格时具有焦点的Component。voidsetInputValue(Object newValue)设置用户选择或输入的输入值。voidsetMessage(Object newMessage)设置选项窗格的message-object。voidsetMessageType(int newType)设置选项窗格的消息类型。voidsetOptions(Object[] newOptions)设置此窗格显示的选项。voidsetOptionType(int newType)设置要显示的选项。static voidsetRootFrame(Frame newRootFrame)设置要用于未提供框架的类方法的框架。voidsetSelectionValues(Object[] newValues)设置窗格的输入选择值,该窗格为用户提供可供选择的项列表。voidsetUI(OptionPaneUI ui)设置实现此组件的L&F的UI对象。voidsetValue(Object newValue)设置用户选择的值。voidsetWantsInput(boolean newValue)设置wantsInput属性。static intshowConfirmDialog(Component parentComponent, Object message)使用选项Yes , No和Cancel打开一个对话框; 使用标题, 选择一个选项 。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)打开一个内部对话框面板,其中包含选项Yes , No和Cancel ; 使用标题, 选择一个选项 。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已经改变的通知。-
声明方法的类 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, 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, update
-
声明方法的类 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, validateTree
-
声明方法的类 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, hide, 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
-
-
-
-
字段详细信息
-
UNINITIALIZED_VALUE
public static final Object 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
没有使用图标。- 另请参见:
- 常数字段值
-
INITIAL_VALUE_PROPERTY
public static final String INITIAL_VALUE_PROPERTY
绑定属性名称为initialValue。- 另请参见:
- 常数字段值
-
OPTION_TYPE_PROPERTY
public static final String OPTION_TYPE_PROPERTY
绑定属性名称为optionType。- 另请参见:
- 常数字段值
-
SELECTION_VALUES_PROPERTY
public static final String SELECTION_VALUES_PROPERTY
绑定属性名称为selectionValues。- 另请参见:
- 常数字段值
-
INITIAL_SELECTION_VALUE_PROPERTY
public static final String INITIAL_SELECTION_VALUE_PROPERTY
绑定属性名称为initialSelectionValue。- 另请参见:
- 常数字段值
-
INPUT_VALUE_PROPERTY
public static final String INPUT_VALUE_PROPERTY
绑定属性名称为inputValue。- 另请参见:
- 常数字段值
-
WANTS_INPUT_PROPERTY
public static final String WANTS_INPUT_PROPERTY
绑定属性名称为wantsInput。- 另请参见:
- 常数字段值
-
icon
protected transient Icon icon
窗格中使用的图标。
-
message
protected transient Object message
要显示的消息。
-
options
protected transient Object[] options
显示给用户的选项。
-
initialValue
protected transient Object initialValue
应在options初始选择的options。
-
messageType
protected int messageType
消息类型。
-
optionType
protected int optionType
选项类型的一个DEFAULT_OPTION,YES_NO_OPTION,YES_NO_CANCEL_OPTION或OK_CANCEL_OPTION。
-
value
protected transient Object value
当前选择的值,将是有效选项,或UNINITIALIZED_VALUE或null。
-
selectionValues
protected transient Object[] selectionValues
用户可以选择的值数组。 外观将提供UI组件以从中进行选择。
-
inputValue
protected transient Object inputValue
用户输入的值。
-
initialSelectionValue
protected transient Object initialSelectionValue
要在selectionValues选择的初始值。
-
wantsInput
protected boolean wantsInput
如果为true,则将向用户提供UI小部件以获取输入。
-
-
构造方法详细信息
-
JOptionPane
public JOptionPane()
使用测试消息创建JOptionPane。
-
JOptionPane
public JOptionPane(Object message)
创建JOptionPane的实例以使用纯文本消息类型和UI提供的默认选项显示消息。- 参数
-
message- 要显示的Object
-
JOptionPane
public JOptionPane(Object message, int messageType)
创建JOptionPane的实例以显示具有指定消息类型和默认选项的消息,- 参数
-
message- 要显示Object -
messageType-要显示的消息的类型:ERROR_MESSAGE,INFORMATION_MESSAGE,WARNING_MESSAGE,QUESTION_MESSAGE,或PLAIN_MESSAGE
-
JOptionPane
public JOptionPane(Object message, int messageType, int optionType)
创建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
public JOptionPane(Object message, int messageType, int optionType, Icon icon)
创建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
public JOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options)
创建JOptionPane的实例以显示具有指定消息类型,图标和选项的消息。 最初未选择任何选项。选项对象应包含
Components(直接添加)或Strings(包含在JButton)的JButton。 如果您提供ComponentS,你必须确保当Component点击它的消息setValue在创建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图像 -
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时才有意义
-
-
方法详细信息
-
showInputDialog
public static String showInputDialog(Object message) throws HeadlessException
显示请求用户输入的问题消息对话框。 该对话框使用默认框架,这通常意味着它在屏幕上居中。- 参数
-
message- 要显示的Object - 结果
- 用户的输入
- 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
showInputDialog
public static String showInputDialog(Object message, Object initialSelectionValue)
显示请求用户输入的问题消息对话框,输入值初始化为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 - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
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 - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
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-的阵列Objects表示给出可能选择 -
initialSelectionValue- 用于初始化输入字段的值 - 结果
-
用户输入,或
null表示用户取消了输入 - 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
showMessageDialog
public static void showMessageDialog(Component parentComponent, Object message) throws HeadlessException
打开一个标题为“消息”的信息消息对话框。- 参数
-
parentComponent- 确定显示对话框的Frame; 如果null,或者如果parentComponent没有Frame,则使用默认值Frame -
message- 要显示的Object - 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
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 - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
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 - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
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 - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
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-一个int指定对话框上的可用选项:YES_NO_OPTION,YES_NO_CANCEL_OPTION,或OK_CANCEL_OPTION - 结果
- 一个int,表示用户选择的选项
- 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
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 - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
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- 要显示的对象 -
title- 对话框的标题字符串 -
optionType-一个int指定对话框上的可用选项:YES_NO_OPTION,YES_NO_CANCEL_OPTION,或OK_CANCEL_OPTION -
messageType-一个int指定消息种类,主要用于确定来自插入外观的图标:ERROR_MESSAGE,INFORMATION_MESSAGE,WARNING_MESSAGE,QUESTION_MESSAGE,或PLAIN_MESSAGE -
icon- 要在对话框中显示的图标 - 结果
- 一个int,表示用户选择的选项
- 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
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 - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
createDialog
public JDialog createDialog(Component parentComponent, String title) throws HeadlessException
创建并返回JDialog包装this中心位于parentComponent中的parentComponent。title是返回的对话框的标题。 返回的JDialog将无法由用户调整大小,但是程序可以在JDialog实例上调用setResizable来更改此属性。 返回的JDialog将被设置为一旦关闭,或者用户单击其中一个按钮,将相应地设置optionpane的value属性并关闭对话框。 每次使对话框可见时,它都会将选项窗格的value属性重置为JOptionPane.UNINITIALIZED_VALUE以确保用户的后续操作正确关闭对话框。- 参数
-
parentComponent- 确定显示对话框的框架; 如果parentComponent没有Frame,则使用默认值Frame -
title- 对话框的标题字符串 - 结果
-
包含此实例的新
JDialog - 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
createDialog
public JDialog createDialog(String title) throws HeadlessException
创建并返回具有指定标题的新的无父对象JDialog。 返回的JDialog将无法由用户调整大小,但是程序可以在JDialog实例上调用setResizable来更改此属性。 返回的JDialog将被设置为一旦关闭,或者用户单击其中一个按钮,将相应地设置optionpane的value属性并关闭对话框。 每次使对话框可见时,它都会将选项窗格的value属性重置为JOptionPane.UNINITIALIZED_VALUE以确保用户的后续操作正确关闭对话框。- 参数
-
title- 对话框的标题字符串 - 结果
-
包含此实例的新
JDialog - 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 从以下版本开始:
- 1.6
- 另请参见:
-
GraphicsEnvironment.isHeadless()
-
showInternalMessageDialog
public static void showInternalMessageDialog(Component parentComponent, Object 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
public static int showInternalConfirmDialog(Component parentComponent, Object message)
打开一个内部对话框面板,其中包含选项Yes , No和Cancel ; 使用标题, 选择一个选项 。- 参数
-
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对象呈现为字符串; 其它的目的将被转换为String使用toString方法 -
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对象呈现为字符串; 其它的目的将被转换为String使用toString方法 -
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对象呈现为字符串; 其它的目的将被转换为String使用toString方法 -
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对象呈现为字符串。 其它的目的将被转换为String使用toString方法 -
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 - 结果
-
一个整数,表示用户选择的选项,如果用户关闭了Dialog,
CLOSED_OPTION
-
showInternalInputDialog
public static String showInternalInputDialog(Component parentComponent, Object message)
显示内部问题消息对话框,请求来自用户的输入为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是提示用户的初始值。 它是由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-的阵列Objects即给出可能选择 -
initialSelectionValue- 用于初始化输入字段的值 - 结果
-
用户输入,或
null表示用户取消了输入
-
createInternalFrame
public JInternalFrame createInternalFrame(Component parentComponent, String title)
创建并返回JInternalFrame的实例。 使用指定的标题创建内部框架,并包装JOptionPane。 返回的JInternalFrame被添加到JDesktopPane祖先parentComponent,或者组件为父,如果其祖先不是JDesktopPane,或者如果parentComponent没有父,则抛出RuntimeException。- 参数
-
parentComponent- 内部框架的父级Component -
title- 要在框架的标题栏中显示的String - 结果
-
a
JInternalFrame包含JOptionPane - 异常
-
RuntimeException- 如果parentComponent没有有效的父级
-
getFrameForComponent
public static Frame getFrameForComponent(Component parentComponent) throws HeadlessException
返回指定的组件Frame。- 参数
-
parentComponent-将Component来检查Frame - 结果
-
该
Frame包含组件,或getRootFrame如果组件为null,或者没有有效Frame父 - 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 另请参见:
-
getRootFrame(),GraphicsEnvironment.isHeadless()
-
getDesktopPaneForComponent
public static JDesktopPane getDesktopPaneForComponent(Component parentComponent)
返回指定组件的桌面窗格。- 参数
-
parentComponent- 检查桌面的Component - 结果
-
所述
JDesktopPane包含该组件,或null如果组件是null或不具有祖先是JInternalFrame
-
setRootFrame
public static void setRootFrame(Frame newRootFrame)
设置要用于未提供框架的类方法的框架。注意:建议您提供有效的父级,而不是使用此方法。
- 参数
-
newRootFrame- 要使用的默认值Frame
-
getRootFrame
public static Frame getRootFrame() throws HeadlessException
返回Frame以用于未提供框架的类方法。- 结果
-
要使用的默认
Frame - 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 另请参见:
-
setRootFrame(java.awt.Frame),GraphicsEnvironment.isHeadless()
-
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对象 - 另请参见:
-
UIDefaults.getUI(javax.swing.JComponent)
-
getUI
public OptionPaneUI getUI()
返回实现此组件的L&F的UI对象。- 重写:
-
getUI类JComponent - 结果
-
OptionPaneUI对象
-
updateUI
public void updateUI()
来自UIManager的L&F已更改的通知。 使用UIManager的最新版本替换当前UI对象。- 重写:
-
updateUI在类JComponent - 另请参见:
-
JComponent.updateUI()
-
getUIClassID
@BeanProperty(bound=false) public String getUIClassID()
返回实现此组件的L&F的UI类的名称。- 重写:
-
getUIClassID类JComponent - 结果
- 字符串“OptionPaneUI”
- 另请参见:
-
JComponent.getUIClassID(),UIDefaults.getUI(javax.swing.JComponent)
-
setMessage
@BeanProperty(preferred=true, description="The optionpane\'s message object.") public void setMessage(Object newMessage)
设置选项窗格的message-object。- 参数
-
newMessage- 显示Object - 另请参见:
-
getMessage()
-
getMessage
public Object getMessage()
返回此窗格显示的消息对象。- 结果
-
显示的
Object - 另请参见:
-
setMessage(java.lang.Object)
-
setIcon
@BeanProperty(preferred=true, description="The option pane\'s type icon.") public void setIcon(Icon newIcon)
设置要显示的图标。 如果null,则外观不提供图标。- 参数
-
newIcon- 要显示的Icon - 另请参见:
-
getIcon()
-
getIcon
public Icon getIcon()
返回此窗格显示的图标。- 结果
-
显示的
Icon - 另请参见:
-
setIcon(javax.swing.Icon)
-
setValue
@BeanProperty(preferred=true, description="The option pane\'s value object.") public void setValue(Object newValue)
设置用户选择的值。- 参数
-
newValue- 所选值 - 另请参见:
-
getValue()
-
getValue
public Object getValue()
返回用户选择的值。UNINITIALIZED_VALUE暗示用户尚未做出选择,null表示用户关闭窗口null选择任何内容。 否则返回的值将是此对象中定义的选项之一。- 结果
-
该
Object由用户选择UNINITIALIZED_VALUE如果用户尚未作出一个选择,或null如果用户关闭了窗口不作选择 - 另请参见:
-
setValue(java.lang.Object)
-
setOptions
@BeanProperty(description="The option pane\'s options objects.") public void setOptions(Object[] newOptions)
设置此窗格显示的选项。 如果newOptions的元素是Component,则会将其直接添加到窗格中,否则会为该元素创建一个按钮。- 参数
-
newOptions-的阵列Objects创造的按钮,用户可以点击,或任意Components添加到窗格 - 另请参见:
-
getOptions()
-
getOptions
public Object[] getOptions()
返回用户可以做出的选择。- 结果
-
Objects的数组,提供用户的选择 - 另请参见:
-
setOptions(java.lang.Object[])
-
setInitialValue
@BeanProperty(preferred=true, description="The option pane\'s initial value object.") public void setInitialValue(Object newInitialValue)
设置要启用的初始值 - 最初显示窗格时具有焦点的Component。- 参数
-
newInitialValue- 获得初始键盘焦点的Object - 另请参见:
-
getInitialValue()
-
getInitialValue
public Object getInitialValue()
返回初始值。- 结果
-
获得初始键盘焦点的
Object - 另请参见:
-
setInitialValue(java.lang.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()
-
getMessageType
public int getMessageType()
返回消息类型。- 结果
- 一个指定消息类型的整数
- 另请参见:
-
setMessageType(int)
-
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(),setOptions(java.lang.Object[])
-
getOptionType
public int getOptionType()
返回显示的选项类型。- 结果
- 一个整数,指定用户可选择的选项
- 另请参见:
-
setOptionType(int)
-
setSelectionValues
@BeanProperty(description="The option pane\'s selection values.") public void setSelectionValues(Object[] newValues)
设置窗格的输入选择值,该窗格为用户提供可供选择的项列表。 (UI提供了一个用于选择其中一个值的小部件。)null值意味着用户可以输入他们想要的任何内容,通常是通过JTextField。将
wantsInput设置为true。 使用setInitialSelectionValue指定最初选择的值。 启用窗格后,将inputValue设置为用户选择的值。- 参数
-
newValues- 要显示的用户的数组Objects(通常在列表或组合框中),用户可以从中进行选择 - 另请参见:
-
setWantsInput(boolean),setInitialSelectionValue(java.lang.Object),getSelectionValues()
-
getSelectionValues
public Object[] getSelectionValues()
返回输入选择值。- 结果
-
用户可以选择的
Objects数组 - 另请参见:
-
setSelectionValues(java.lang.Object[])
-
setInitialSelectionValue
@BeanProperty(description="The option pane\'s initial selection value object.") public void setInitialSelectionValue(Object newValue)
将最初显示为选定的输入值设置为用户。 仅在wantsInput为真时使用。- 参数
-
newValue- 最初选择的值 - 另请参见:
-
setSelectionValues(java.lang.Object[]),getInitialSelectionValue()
-
getInitialSelectionValue
public Object getInitialSelectionValue()
返回最初选择给用户显示的输入值。
-
setInputValue
@BeanProperty(preferred=true, description="The option pane\'s input value object.") public void setInputValue(Object newValue)
设置用户选择或输入的输入值。 仅在wantsInput为真时使用。 请注意,此方法由选项窗格在内部调用(响应用户操作),通常不应由客户端程序调用。 要将最初显示为选定的输入值设置为用户,请使用setInitialSelectionValue。- 参数
-
newValue- 用于设置用户指定值的Object(通常在文本字段中) - 另请参见:
-
setSelectionValues(java.lang.Object[]),setInitialSelectionValue(java.lang.Object),setWantsInput(boolean),getInputValue()
-
getInputValue
public Object getInputValue()
如果wantsInput为true,则返回用户输入的值。- 结果
-
用户指定的
Object,如果是其中一个对象,或者是String如果它是在字段中键入的值 - 另请参见:
-
setSelectionValues(java.lang.Object[]),setWantsInput(boolean),setInputValue(java.lang.Object)
-
getMaxCharactersPerLineCount
@BeanProperty(bound=false) public int 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的输入组件以允许用户输入值。 - 另请参见:
-
setSelectionValues(java.lang.Object[]),setInputValue(java.lang.Object)
-
getWantsInput
public boolean getWantsInput()
返回wantsInput属性的值。- 结果
- 如果将提供输入组件,则为true
- 另请参见:
-
setWantsInput(boolean)
-
selectInitialValue
public void selectInitialValue()
请求选择初始值,将焦点设置为初始值。 在包含选项窗格的窗口可见后,应调用此方法。
-
paramString
protected String paramString()
返回此JOptionPane的字符串表示JOptionPane。 此方法仅用于调试目的,返回字符串的内容和格式可能因实现而异。 返回的字符串可能为空,但可能不是null。- 重写:
-
paramString,类JComponent - 结果
-
此
JOptionPane的字符串表示JOptionPane
-
getAccessibleContext
@BeanProperty(bound=false, expert=true, description="The AccessibleContext associated with this option pane") public AccessibleContext getAccessibleContext()
返回与此JOptionPane关联的AccessibleContext。 对于选项窗格中,AccessibleContext需要一个形式AccessibleJOptionPane。 如有必要,将创建一个新的AccessibleJOptionPane实例。- Specified by:
-
getAccessibleContext,界面Accessible - 重写:
-
getAccessibleContext在类Component - 结果
- 一个AccessibleJOptionPane,用作此AccessibleJOptionPane的AccessibleContext
-
-