gpt4 book ai didi

java - 如何在 Java (Swing) 中添加对话框?

转载 作者:行者123 更新时间:2023-12-02 00:42:35 26 4
gpt4 key购买 nike

Possible Duplicate:
Simple popup java form with at least two fields

我正在尝试制作一个具有多个按钮、输入文本的位置等的对话框。我正在使用本教程 - http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html ,但它没有任何关于拥有多个项目的信息。有办法做到这一点吗?

最佳答案

许多 showXXXXDialog 方法都将对象作为参数之一。如果该对象是一个字符串,它将显示一个字符串。如果该对象是包含按钮、输入字段和其他小部件的容器,它将显示该内容。

引用http://download.oracle.com/javase/6/docs/api/javax/swing/JOptionPane.html

Parameters:
The parameters to these methods follow consistent patterns:


parentComponent

Defines the Component that is to be the parent of this dialog box. It is used in two ways: the Frame that contains it is used as the Frame parent 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 be null, in which case a default Frame is 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 String or String constant. However, the type of this parameter is actually Object. 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 Component is displayed in the dialog.

Icon The Icon is wrapped in a JLabel and displayed in the dialog.

others The object is converted to a String by calling its toString method. The result is wrapped in a JLabel and displayed.

关于java - 如何在 Java (Swing) 中添加对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5905881/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com