The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
A Dialog window is an independent sub window meant to carry temporary notice apart from the main Swing Application Window. 对话框窗口是一个独立的子窗口,用于在主Swing应用程序窗口之外携带临时通知。Most Dialogs present an error message or warning to a user, but Dialogs can present images, directory trees, or just about anything compatible with the main Swing Application that manages them.大多数对话框向用户显示错误消息或警告,但对话框可以显示图像、目录树或与管理它们的主Swing应用程序兼容的任何内容。
For convenience, several Swing component classes can directly instantiate and display dialogs. 为了方便起见,几个Swing组件类可以直接实例化和显示对话框。To create simple, standard dialogs, you use the 要创建简单的标准对话框,可以使用JOptionPane class. JOptionPane类。The ProgressMonitor class can put up a dialog that shows the progress of an operation. ProgressMonitor类可以设置一个对话框,显示操作的进度。Two other classes, 另外两个类JColorChooser and JFileChooser, also supply standard dialogs. JColorChooser和JFileChooser也提供标准对话框。To bring up a print dialog, you can use the Printing API. 要打开打印对话框,可以使用打印API。To create a custom dialog, use the 要创建自定义对话框,请直接使用JDialog class directly.JDialog类。
The code for simple dialogs can be minimal. 简单对话框的代码可以是最少的。For example, here is an informational dialog:例如,下面是一个信息对话框:

Here is the code that creates and shows it:下面是创建并显示它的代码:
JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be green.");
The rest of this section covers the following topics:本节其余部分包括以下主题:
Every dialog is dependent on a Frame component. 每个对话框都依赖于框架构件。When that Frame is destroyed, so are its dependent Dialogs. 当该帧被破坏时,其相关对话框也被破坏。When the frame is iconified, its dependent Dialogs also disappear from the screen. 当框架图标化时,其相关对话框也从屏幕上消失。When the frame is deiconified, its dependent Dialogs return to the screen. 当帧被去锥形化时,其相关对话框返回到屏幕。A swing JDialog class inherits this behavior from the AWT swing JDialog类从AWTDialog class.Dialog类继承此行为。
A Dialog can be modal. 对话框可以是模态的。When a modal Dialog is visible, it blocks user input to all other windows in the program. 当模式对话框可见时,它会阻止用户输入程序中的所有其他窗口。JOptionPane creates JOptionPane创建模态的JDialogs that are modal. JDialog。To create a non-modal Dialog, you must use the 要创建非模态对话框,必须直接使用JDialog class directly.JDialog类。
Starting with JDK 7, you can modify dialog window modality behavior using the new Modality API. 从JDK 7开始,您可以使用新的模态API修改对话框窗口模态行为。See The New Modality API for details.有关详细信息,请参阅新的模态API。
The JDialog class is a subclass of the AWT java.awt.Dialog class. JDialog类是AWT java.awt.Dialog类的一个子类。It adds a root pane container and support for a default close operation to the 它为Dialog object . Dialog对象添加了根窗格容器和对默认关闭操作的支持。These are the same features that 这些功能与JFrame has, and using JDialog directly is very similar to using JFrame. JFrame相同,直接使用JDialog与使用JFrame非常相似。If you're going to use 如果您打算直接使用JDialog directly, then you should understand the material in Using Top-Level Containers and How to Make Frames, especially Responding to Window-Closing Events.JDialog,那么您应该了解使用顶级容器的材料,以及如何制作框架,尤其是响应窗口关闭事件。
Even when you use 即使使用JOptionPane to implement a dialog, you're still using a JDialog behind the scenes. JOptionPane实现对话框,您仍然在幕后使用JDialog。The reason is that 原因是JOptionPane is simply a container that can automatically create a JDialog and add itself to the JDialog's content pane.JOptionPane只是一个容器,可以自动创建JDialog并将其自身添加到JDialog的内容窗格中。
Here is a picture of an application that displays dialogs.下面是显示对话框的应用程序的图片。


JOptionPane功能Using 使用JOptionPane, you can quickly create and customize several different kinds of dialogs. JOptionPane,您可以快速创建和自定义几种不同类型的对话框。JOptionPane provides support for laying out standard dialogs, providing icons, specifying the dialog title and text, and customizing the button text. 提供对布局标准对话框、提供图标、指定对话框标题和文本以及自定义按钮文本的支持。Other features allow you to customize the components the dialog displays and specify where the dialog should appear onscreen. 其他功能允许您自定义对话框显示的组件,并指定对话框在屏幕上的显示位置。You can even specify that an option pane put itself into an internal frame (您甚至可以指定选项窗格将自身置于内部框架(JInternalFrame) instead of a JDialog.JInternalFrame)中,而不是JDialog中。
When you create a 创建JOptionPane, look-and-feel-specific code adds components to the JOptionPane and determines the layout of those components.JOptionPane时,特定于外观的代码将组件添加到JOptionPane,并确定这些组件的布局。
JOptionPane's icon support lets you easily specify which icon the dialog displays. JOptionPane的图标支持允许您轻松指定对话框显示的图标。You can use a custom icon, no icon at all, or any one of four standard 您可以使用自定义图标、完全不使用图标或四个标准JOptionPane icons (question, information, warning, and error). JOptionPane图标(问题、信息、警告和错误)中的任何一个。Each look and feel has its own versions of the four standard icons. 每个外观都有四个标准图标的各自版本。The following figure shows the icons used in the Java (and Windows) look and feel.下图显示了Java(和Windows)外观中使用的图标。
| question | ![]() |
![]() |
| information | ![]() |
![]() |
| warning | ![]() |
![]() |
| error | ![]() |
![]() |
For most simple modal dialogs, you create and show the dialog using one of 对于大多数简单的模式对话框,您可以使用JOptionPane's showXxxDialog methods. JOptionPane的showXxxDialog方法之一创建和显示对话框。If your dialog should be an internal frame, then add 如果您的对话框应该是内部框架,则在Internal after show for example, showMessageDialog changes to showInternalMessageDialog. show后面添加Internal例如,showMessageDialog更改为showInternalMessageDialog。If you need to control the dialog window-closing behavior or if you do not want the dialog to be modal, then you should directly instantiate 如果您需要控制对话框窗口的关闭行为,或者您不希望对话框处于模态状态,那么您应该直接实例化JOptionPane and add it to a JDialog instance. JOptionPane并将其添加到JDialog实例中。Then invoke 然后在setVisible(true) on the JDialog to make it appear.JDialog上调用setVisible(true)使其显示。
The two most useful 两种最有用的showXxxDialog methods are showMessageDialog and showOptionDialog. showXxxDialog方法是showMessageDialog和showOptionDialog。The showMessageDialog method displays a simple, one-button dialog. showMessageDialog方法显示一个简单的单键对话框。The showOptionDialog method displays a customized dialog it can display a variety of buttons with customized button text, and can contain a standard text message or a collection of components.showOptionDialog方法显示自定义对话框它可以显示带有自定义按钮文本的各种按钮,并且可以包含标准文本消息或组件集合。
The other two 其他两种showXxxDialog methods are used less often. showXxxDialog方法的使用频率较低。The showConfirmDialog方法要求用户确认某些内容,但显示标准按钮文本(例如,是/否或本地化的等效文本),而不是根据用户情况定制的按钮文本(比如,开始/取消)。showConfirmDialog method asks the user to confirm something, but presents standard button text (Yes/No or the localized equivalent, for example) rather than button text customized to the user situation (Start/Cancel, for example). A fourth method, 第四种方法showInputDialog, is designed to display a modal dialog that gets a string from the user, using either a text field, an uneditable combo box or a list.showInputDialog用于显示一个模式对话框,该对话框使用文本字段、不可编辑的组合框或列表从用户处获取字符串。
Here are some examples, taken from 下面是一些使用DialogDemo.java, of using showMessageDialog, showOptionDialog, and the JOptionPane constructor. showMessageDialog、showOptionDialog和JOptionPane构造函数的示例,这些示例取自DialogDemo.java。For more example code, see 有关更多示例代码,请参阅DialogDemo.java and the other programs listed in Examples that Use Dialogs.DialogDemo.java和使用对话框的示例中列出的其他程序。
showMessageDialogshowMessageDialog:showMessageDialog的一些示例:
![]() |
//default title and icon
JOptionPane.showMessageDialog(frame,
"Eggs are not supposed to be green."); |
//custom title, warning icon
JOptionPane.showMessageDialog(frame,
"Eggs are not supposed to be green.",
"Inane warning",
JOptionPane.WARNING_MESSAGE); | |
//custom title, error icon
JOptionPane.showMessageDialog(frame,
"Eggs are not supposed to be green.",
"Inane error",
JOptionPane.ERROR_MESSAGE); | |
//custom title, no icon
JOptionPane.showMessageDialog(frame,
"Eggs are not supposed to be green.",
"A plain message",
JOptionPane.PLAIN_MESSAGE); | |
//custom title, custom icon
JOptionPane.showMessageDialog(frame,
"Eggs are not supposed to be green.",
"Inane custom dialog",
JOptionPane.INFORMATION_MESSAGE,
icon); |
showOptionDialog![]() |
//Custom button text
Object[] options = {"Yes, please",
"No, thanks",
"No eggs, no ham!"};
int n = JOptionPane.showOptionDialog(frame,
"Would you like some green eggs to go "
+ "with that ham?",
"A Silly Question",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[2]); |
JOptionPane (constructor)JOptionPane with the specified buttons, icons, message, title, and so on. JOptionPane。JDialog, register a property-change listener on the option pane, and show the dialog. JDialog,在选项窗格上注册属性更改侦听器,并显示对话框。![]() |
final JOptionPane optionPane = new JOptionPane(
"The only way to close this dialog is by\n"
+ "pressing one of the following buttons.\n"
+ "Do you understand?",
JOptionPane.QUESTION_MESSAGE,
JOptionPane.YES_NO_OPTION); |
The arguments to all of the 所有showXxxDialog methods and JOptionPane constructors are standardized, though the number of arguments for each method and constructor varies. showXxxDialog方法和JOptionPane构造函数的参数都是标准化的,尽管每个方法和构造函数的参数数量各不相同。The following list describes each argument. 下表描述了每个参数。To see the exact list of arguments for a particular method, see The Dialog API.要查看特定方法的参数的确切列表,请参阅对话框API。
Component parentComponentshowXxxDialog method is always the parent component, which must be a Frame, a component inside a Frame, or null. showXxxDialog方法的第一个参数始终是父组件,它必须是框架、框架内的组件或null。null,则外观将为对话框选择适当的位置通常是屏幕的中心并且该对话框不必遵循任何可见帧或对话框的聚焦行为。The JOptionPane constructors do not include this argument. JOptionPane构造函数不包含此参数。Instead, you specify the parent frame when you create the 相反,您可以在创建包含JDialog that contains the JOptionPane, and you use the JDialog setLocationRelativeTo method to set the dialog position.JOptionPane的JDialog时指定父框架,并使用JDialog setLocationRelativeTo方法设置对话框位置。
Object message\n) characters inside the message string. \n),可以将消息拆分为多行。"Complete the sentence:\n \"Green eggs and...\""
String titleint optionTypeDEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION, OK_CANCEL_OPTION.DEFAULT_OPTION、YES_NO_OPTION、YES_NO_CANCEL_OPTION、OK_CANCEL_OPTION。int messageTypePLAIN_MESSAGE (no icon), ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE.PLAIN_MESSAGE(无图标)、ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE和QUESTION_MESSAGE。Icon iconObject[] optionsObject initialValueYou can either let the option pane display its default icon or specify the icon using the message type or icon argument. 您可以让选项窗格显示其默认图标,也可以使用消息类型或图标参数指定图标。By default, an option pane created with 默认情况下,使用showMessageDialog displays the information icon, one created with showConfirmDialog or showInputDialog displays the question icon, and one created with a JOptionPane constructor displays no icon. showMessageDialog创建的选项窗格显示信息图标,使用showConfirmDialog或showInputDialog创建一个选项窗格显示问题图标,使用JOptionPane构造函数创建的选项面板不显示图标。To specify that the dialog display a standard icon or no icon, specify the message type corresponding to the icon you desire. 要指定对话框显示标准图标或无图标,请指定与所需图标对应的消息类型。To specify a custom icon, use the icon argument. 要指定自定义图标,请使用图标参数。The icon argument takes precedence over the message type; as long as the icon argument has a non-null value, the dialog displays the specified icon.图标参数优先于消息类型;只要icon参数具有非空值,对话框就会显示指定的图标。
When you use 使用JOptionPane to create a dialog, you can either use the standard button text (which might vary by look and feel and locale) or specify different text. JOptionPane创建对话框时,您可以使用标准按钮文本(可能因外观和区域设置而有所不同),也可以指定不同的文本。By default, the option pane type determines how many buttons appear. 默认情况下,选项窗格类型决定显示多少按钮。For example, 例如,YES_NO_OPTION dialogs have two buttons, and YES_NO_CANCEL_OPTION dialogs have three buttons.YES_NO_OPTION对话框有两个按钮,而YES_NO_CANCEL_OPTION对话框有三个按钮。
The following code, taken from 下面的代码取自DialogDemo.java, creates two Yes/No dialogs. DialogDemo.java,创建了两个是/否对话框。The first dialog is implemented with 第一个对话框由showConfirmDialog, which uses the look-and-feel wording for the two buttons. showConfirmDialog实现,它使用了两个按钮的外观措辞。The second dialog uses 第二个对话框使用showOptionDialog so it can customize the wording. showOptionDialog,因此可以自定义措辞。With the exception of wording changes, the dialogs are identical.除了措辞变化外,对话框是相同的。
![]() |
//default icon, custom title
int n = JOptionPane.showConfirmDialog(
frame,
"Would you like green eggs and ham?",
"An Inane Question",
JOptionPane.YES_NO_OPTION); |
![]() |
Object[] options = {"Yes, please",
"No way!"};
int n = JOptionPane.showOptionDialog(frame,
"Would you like green eggs and ham?",
"A Silly Question",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, //do not use a custom Icon
options, //the titles of buttons
options[0]); //default button title |
As the previous code snippets showed, the 如前面的代码片段所示,showMessageDialog, showConfirmDialog, and showOptionDialog methods return an integer indicating the user's choice. showMessageDialog、showConfirmDialog和showOptionDialog方法返回一个指示用户选择的整数。The values for this integer are 该整数的值为YES_OPTION, NO_OPTION, CANCEL_OPTION, OK_OPTION, and CLOSED_OPTION. YES_OPTION、NO_OPTION、CANCEL_OPTION、OK_OPTION和CLOSED_OPTION。Except for 除了CLOSED_OPTION, each option corresponds to the button the user pressed. CLOSED_OPTION之外,每个选项都对应于用户按下的按钮。When 返回CLOSED_OPTION is returned, it indicates that the user closed the dialog window explicitly, rather than by choosing a button inside the option pane.CLOSED_OPTION时,表示用户显式关闭对话框窗口,而不是在选项窗格中选择按钮。
Even if you change the strings that the standard dialog buttons display, the return value is still one of the pre-defined integers. 即使更改了标准对话框按钮显示的字符串,返回值仍然是预定义的整数之一。For example, a 例如,YES_NO_OPTION dialog always returns one of the following values: YES_OPTION, NO_OPTION, or CLOSED_OPTION.YES_NO_OPTION对话框始终返回以下值之一:YES_OPTION、NO_OPTION或CLOSED_OPTION。
The only form of showXxxDialog that does not return an integer is showInputDialog, which returns an Object instead. showXxxDialog唯一不返回整数的形式是showInputDialog,它返回一个对象。This 该Object is generally a String reflecting the user's choice. Object通常是反映用户选择的String。Here is an example of using 下面是一个使用showInputDialog to create a dialog that lets the user choose one of three strings:showInputDialog创建对话框的示例,该对话框允许用户从三个字符串中选择一个:

Object[] possibilities = {"ham", "spam", "yam"};
String s = (String)JOptionPane.showInputDialog(
frame,
"Complete the sentence:\n"
+ "\"Green eggs and...\"",
"Customized Dialog",
JOptionPane.PLAIN_MESSAGE,
icon,
possibilities,
"ham");
//If a string was returned, say so.
if ((s != null) && (s.length() > 0)) {
setLabel("Green eggs and... " + s + "!");
return;
}
//If you're here, the return value was null/empty.
setLabel("Come on, finish the sentence!");If you do not care to limit the user's choices, you can either use a form of the 如果您不想限制用户的选择,您可以使用使用较少参数的showInputDialog method that takes fewer arguments or specify null for the array of objects. showInputDialog方法,或者为对象数组指定null。In the Java look and feel, substituting 在Java look and feel中,用null for possibilities results in a dialog that has a text field and looks like this:null替换possibilities会导致一个对话框,该对话框具有文本字段,如下所示:

Because the user can type anything into the text field, you might want to check the returned value and ask the user to try again if it is invalid. 由于用户可以在文本字段中键入任何内容,因此您可能需要检查返回的值,并要求用户在该值无效时重试。Another approach is to create a custom dialog that validates the user-entered data before it returns. 另一种方法是创建一个自定义对话框,在返回之前验证用户输入的数据。See 有关验证数据的示例,请参阅CustomDialog.java for an example of validating data.CustomDialog.java。
If you're designing a custom dialog, you need to design your dialog's API so that you can query the dialog about what the user chose. 如果要设计自定义对话框,则需要设计对话框的API,以便可以查询用户选择的对话框。For example, 例如,CustomDialog has a getValidatedText method that returns the text the user entered.CustomDialog有一个getValidatedText方法,该方法返回用户输入的文本。
By default, when the user clicks a 默认情况下,当用户单击创建的JOptionPane-created button, the dialog closes. JOptionPane按钮时,对话框将关闭。But what if you want to check the user's answer before closing the dialog? 但是,如果您想在关闭对话框之前检查用户的答案,该怎么办?In this case, you must implement your own property change listener so that when the user clicks a button, the dialog does not automatically close.在这种情况下,您必须实现自己的属性更改侦听器,以便当用户单击按钮时,对话框不会自动关闭。
DialogDemo contains two dialogs that implement a property change listener. 包含两个实现属性更改侦听器的对话框。One of these dialogs is a custom modal dialog, implemented in 其中一个对话框是在CustomDialog, that uses JOptionPane both to get the standard icon and to get layout assistance. CustomDialog中实现的自定义模式对话框,它使用JOptionPane来获取标准图标和布局帮助。The other dialog, whose code is below, uses a standard Yes/No 另一个对话框(其代码如下)使用标准的是/否JOptionPane. JOptionPane。Though this dialog is rather useless as written, its code is simple enough that you can use it as a template for more complex dialogs.虽然这个对话框在编写时相当无用,但它的代码非常简单,可以将其用作更复杂对话框的模板。
Besides setting the property change listener, the following code also calls the 除了设置属性更改监听器外,以下代码还调用JDialog's setDefaultCloseOperation method and implements a window listener that handles the window close attempt properly. JDialog的setDefaultCloseOperation方法,并实现一个窗口监听器,该监听器可以正确处理窗口关闭尝试。If you do not care to be notified when the user closes the window explicitly, then ignore the bold code.如果您不想在用户显式关闭窗口时收到通知,请忽略粗体代码。
final JOptionPane optionPane = new JOptionPane(
"The only way to close this dialog is by\n"
+ "pressing one of the following buttons.\n"
+ "Do you understand?",
JOptionPane.QUESTION_MESSAGE,
JOptionPane.YES_NO_OPTION);
final JDialog dialog = new JDialog(frame,
"Click a button",
true);
dialog.setContentPane(optionPane);
dialog.setDefaultCloseOperation(
JDialog.DO_NOTHING_ON_CLOSE);
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
setLabel("Thwarted user attempt to close window.");
}
});
optionPane.addPropertyChangeListener(
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
if (dialog.isVisible()
&& (e.getSource() == optionPane)
&& (prop.equals(JOptionPane.VALUE_PROPERTY))) {
//If you were going to check something
//before closing the window, you'd do
//it here.
dialog.setVisible(false);
}
}
});
dialog.pack();
dialog.setVisible(true);
int value = ((Integer)optionPane.getValue()).intValue();
if (value == JOptionPane.YES_OPTION) {
setLabel("Good.");
} else if (value == JOptionPane.NO_OPTION) {
setLabel("Try using the window decorations "
+ "to close the non-auto-closing dialog. "
+ "You can't!");
}The following tables list the commonly used 下表列出了常用的JOptionPane and JDialog constructors and methods. JOptionPane和JDialog构造函数和方法。Other methods you're likely to call are defined by the 您可能调用的其他方法由Dialog, Window and Component classes and include pack, setSize, and setVisible.Dialog、Window和Component类定义,包括pack、setSize和setVisible。
The API is listed as follows:API列表如下:
JOptionPane Class Methods)JOptionPane类方法)JOptionPanes DirectlyJOptionPane的方法JDialog Constructors and MethodsJDialog构造函数和方法static void showMessageDialog(Component, Object)static void showMessageDialog(Component, Object, String, int)static void showMessageDialog(Component, Object, String, int, Icon) |
|
static int showOptionDialog(Component, Object, String, int, int, Icon, Object[], Object) |
|
static int showConfirmDialog(Component, Object)static int showConfirmDialog(Component, Object, String, int)static int showConfirmDialog(Component, Object, String, int, int)static int showConfirmDialog(Component, Object, String, int, int, Icon) |
|
static String showInputDialog(Object)static String showInputDialog(Component, Object)static String showInputDialog(Component, Object, String, int)static String showInputDialog(Component, Object, String, int, Icon, Object[], Object) |
|
static void showInternalMessageDialog(...)static void showInternalOptionDialog(...)static void showInternalConfirmDialog(...)static String showInternalInputDialog(...) |
JOptionPane API documentation for the exact list of arguments.JOptionPane API文档。 |
JOptionPane()JOptionPane(Object)JOptionPane(Object, int)JOptionPane(Object, int, int)JOptionPane(Object, int, int, Icon)JOptionPane(Object, int, int, Icon, Object[])JOptionPane(Object, int, int, Icon, Object[], Object) |
JOptionPane instance. JOptionPane实例。 |
static Frame getFrameForComponent(Component)static JDesktopPane getDesktopPaneForComponent(Component) |
JOptionPane class methods that find the frame or desktop pane, respectively, that the specified component is in.JOptionPane类方法,分别查找指定组件所在的框架或桌面窗格。 |
int getMaxCharactersPerLineCount() |
Integer.MAX_VALUE.) Integer.MAX_VALUE。)JOptionPane subclass. JOptionPane子类。JOptionPane op = new JOptionPane("This is the text.") {
public int getMaxCharactersPerLineCount() {
return 5;
}
}; |
JDialog()JDialog(Dialog)JDialog(Dialog, boolean)JDialog(Dialog, String)JDialog(Dialog, String, boolean)JDialog(Dialog, String, boolean, GraphicsConfiguration)JDialog(Frame)JDialog(Frame, boolean)JDialog(Frame, String)JDialog(Frame, String, boolean)JDialog(Frame, String, boolean, GraphicsConfiguration)JDialog(Window owner)JDialog(Window owner, Dialog.ModalityType modalityType)JDialog(Window owner, String title)JDialog(Window owner, String title, Dialog.ModalityType modalityType)JDialog(Window owner, String title, Dialog.ModalityType modalityType, GraphicsConfiguration gc) |
JDialog instance. JDialog实例。Frame argument, if any, is the frame (usually a JFrame object) that the dialog depends on. Frame参数(如果有)是对话框所依赖的框架(通常是JFrame对象)。true to specify a modal dialog, false or absent to specify a non-modal dialog. true以指定模式对话框,将布尔参数设置为false或缺席以指定非模式对话框。 |
void setContentPane(Container)Container getContentPane() |
|
void setDefaultCloseOperation(int)int getDefaultCloseOperation() |
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE (the default). DISPOSE_ON_CLOSE、DO_NOTHING_ON_CLOSE、HIDE_ON_CLOSE(默认值)。 |
void setLocationRelativeTo(Component) |
|
static void setDefaultLookAndFeelDecorated(boolean)static boolean isDefaultLookAndFeelDecorated() |
This table lists examples that use 下表列出了使用JOptionPane or JDialog. JOptionPane或JDialog的示例。To find other examples that use dialogs, see the example lists for progress bars, color choosers, and file choosers.要查找使用对话框的其他示例,请参阅进度条、颜色选择器和文件选择器的示例列表。
DialogDemo,CustomDialog |
JOptionPane and JDialog.JOptionPane和JDialog创建多种对话框。 | |
Framework |
| |
ListDialog |
JOptionPane, except for the utility method getFrameForComponent.getFrameForComponent之外,不使用JOptionPane。 |