- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JOptionPane
-
- All Implemented Interfaces:
-
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 ”一节。虽然
JOptionPane类可能会因为大量方法而复杂,但几乎所有这些类的使用都是单行调用静态的showXxxDialog方法之一,如下所示:
这些方法中的每一个也都有一个Common JOptionPane method names and their descriptions Method Name 描述 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. 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); - 显示选项是/否和消息'选择一个的信息面板:
-
JOptionPane.showConfirmDialog(null, "choose one", "choose one", JOptionPane.YES_NO_OPTION); - 显示内部信息对话框,其中包含选项是/否/取消,并显示“请选择一个”和标题信息:
-
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开始,支持所有JavaBeans的长期存储已经添加到
java.beans包中。 请参阅XMLEncoder。- 从以下版本开始:
- 1.2
- 另请参见:
-
JInternalFrame, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 描述 protected classJOptionPane.AccessibleJOptionPane该类为JOptionPane类实现可访问性支持。-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field 描述 static intCANCEL_OPTION如果选择CANCEL,则从类方法返回值。static intCLOSED_OPTION如果用户关闭窗口而不选择任何东西,则从类方法返回值,这可能被视为CANCEL_OPTION或NO_OPTION。static intDEFAULT_OPTION类型意义Look and Feel不应提供任何选项 - 只能使用JOptionPane的选项。static intERROR_MESSAGE用于错误消息。protected Iconicon窗格中使用的图标。static StringICON_PROPERTY绑定属性名称为icon。static intINFORMATION_MESSAGEX-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如果选择“是”,则从类方法返回值。-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
构造方法摘要
构造方法 Constructor 描述 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的实例以显示具有指定消息类型,图标和选项的消息,并指定最初选择的选项。
-
方法摘要
所有方法 静态方法 接口方法 具体的方法 Modifier and Type 方法 描述 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为真。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)设置选项窗格的消息对象。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)启动对话框,选择是 , 否和取消 ; 标题为“ 选择选项” 。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 inherited from 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, 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
-
Methods inherited from 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, validateTree
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, 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, update
-
-
-
-
字段详细信息
-
UNINITIALIZED_VALUE
public static final Object UNINITIALIZED_VALUE
表示用户尚未选择值。
-
DEFAULT_OPTION
public static final int DEFAULT_OPTION
类型含义Look and Feel不应提供任何选项 - 只能使用JOptionPane的选项。- 另请参见:
- Constant Field Values
-
YES_NO_OPTION
public static final int YES_NO_OPTION
用于showConfirmDialog类型。- 另请参见:
- Constant Field Values
-
YES_NO_CANCEL_OPTION
public static final int YES_NO_CANCEL_OPTION
类型用于showConfirmDialog。- 另请参见:
- Constant Field Values
-
OK_CANCEL_OPTION
public static final int OK_CANCEL_OPTION
类型用于showConfirmDialog。- 另请参见:
- Constant Field Values
-
YES_OPTION
public static final int YES_OPTION
如果选择“是”,则从类方法返回值。- 另请参见:
- Constant Field Values
-
NO_OPTION
public static final int NO_OPTION
如果选择NO,则从类方法返回值。- 另请参见:
- Constant Field Values
-
CANCEL_OPTION
public static final int CANCEL_OPTION
如果选择CANCEL,则从类方法返回值。- 另请参见:
- Constant Field Values
-
OK_OPTION
public static final int OK_OPTION
如果选择OK,则返回值表单类方法。- 另请参见:
- Constant Field Values
-
CLOSED_OPTION
public static final int CLOSED_OPTION
如果用户在没有选择任何东西的情况下关闭窗口,则从类方法返回值,这可能会被视为CANCEL_OPTION或NO_OPTION。- 另请参见:
- Constant Field Values
-
ERROR_MESSAGE
public static final int ERROR_MESSAGE
用于错误消息。- 另请参见:
- Constant Field Values
-
INFORMATION_MESSAGE
public static final int INFORMATION_MESSAGE
X-- 另请参见:
- Constant Field Values
-
WARNING_MESSAGE
public static final int WARNING_MESSAGE
用于警告消息。- 另请参见:
- Constant Field Values
-
QUESTION_MESSAGE
public static final int QUESTION_MESSAGE
用于问题。- 另请参见:
- Constant Field Values
-
PLAIN_MESSAGE
public static final int PLAIN_MESSAGE
没有使用图标。- 另请参见:
- Constant Field Values
-
ICON_PROPERTY
public static final String ICON_PROPERTY
绑定属性名称为icon。- 另请参见:
- Constant Field Values
-
MESSAGE_PROPERTY
public static final String MESSAGE_PROPERTY
绑定属性名称为message。- 另请参见:
- Constant Field Values
-
VALUE_PROPERTY
public static final String VALUE_PROPERTY
绑定属性名称为value。- 另请参见:
- Constant Field Values
-
OPTIONS_PROPERTY
public static final String OPTIONS_PROPERTY
绑定属性名称为option。- 另请参见:
- Constant Field Values
-
INITIAL_VALUE_PROPERTY
public static final String INITIAL_VALUE_PROPERTY
绑定属性名称为initialValue。- 另请参见:
- Constant Field Values
-
MESSAGE_TYPE_PROPERTY
public static final String MESSAGE_TYPE_PROPERTY
绑定属性名称为type。- 另请参见:
- Constant Field Values
-
OPTION_TYPE_PROPERTY
public static final String OPTION_TYPE_PROPERTY
绑定属性名称为optionType。- 另请参见:
- Constant Field Values
-
SELECTION_VALUES_PROPERTY
public static final String SELECTION_VALUES_PROPERTY
绑定属性名称为selectionValues。- 另请参见:
- Constant Field Values
-
INITIAL_SELECTION_VALUE_PROPERTY
public static final String INITIAL_SELECTION_VALUE_PROPERTY
绑定属性名称为initialSelectionValue。- 另请参见:
- Constant Field Values
-
INPUT_VALUE_PROPERTY
public static final String INPUT_VALUE_PROPERTY
绑定属性名称为inputValue。- 另请参见:
- Constant Field Values
-
WANTS_INPUT_PROPERTY
public static final String WANTS_INPUT_PROPERTY
绑定属性名称为wantsInput。- 另请参见:
- Constant Field Values
-
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输入任何他们想要的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
启动对话框,选择是 , 否和取消 ; 标题为“ 选择选项” 。- 参数
-
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将被设置为一旦关闭,或者用户单击其中一个按钮,将选择选项窗格的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将被设置为一旦关闭,或者用户单击其中一个按钮,则选项框的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)
启动一个内部对话面板,选择是 , 否和取消 ; 标题为“ 选择选项” 。- 参数
-
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 - 结果
-
指示用户选择的选项的整数,如果用户关闭对话框,
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输入任何他们想要的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则抛出RuntimeException。- 参数
-
parentComponent- 内部框架的母版Component -
title- 要显示在框架的标题栏中的String - 结果
-
一个
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()
通知从UIManagerL&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)
设置选项窗格的消息对象。- 参数
-
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意味着用户关闭窗口,选择任何东西。 否则返回的值将是此对象中定义的选项之一。- 结果
-
该
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)
设置要显示的选项。 Look and Feel使用选项类型来确定要显示的按钮(除非提供选项)。- 参数
-
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值意味着用户可以通过null输入任何想要的JTextField。将
wantsInput设置为true。 使用setInitialSelectionValue指定最初选择的值。 窗格启用后,inputValue设置为用户选择的值。- 参数
-
newValues- 要显示的用户(通常在列表或组合框中)的用户可以进行选择的数组Objects - 另请参见:
-
setWantsInput(boolean),setInitialSelectionValue(java.lang.Object),getSelectionValues()
-
getSelectionValues
public Object[] getSelectionValues()
返回输入选择值。- 结果
-
Objects的阵列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为真,则提供其父为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
-
-