- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
有没有办法在 JOptionPane.showInputDialog
中创建多个输入而不是一个输入?
最佳答案
是的。您知道您可以将任何 Object
放入大多数 JOptionPane.showXXX 方法
的 Object
参数中,通常是 Object
恰好是一个 JPanel
。
在您的情况下,也许您可以使用其中包含多个 JTextFields
的 JPanel
:
import javax.swing.*;
public class JOptionPaneMultiInput {
public static void main(String[] args) {
JTextField xField = new JTextField(5);
JTextField yField = new JTextField(5);
JPanel myPanel = new JPanel();
myPanel.add(new JLabel("x:"));
myPanel.add(xField);
myPanel.add(Box.createHorizontalStrut(15)); // a spacer
myPanel.add(new JLabel("y:"));
myPanel.add(yField);
int result = JOptionPane.showConfirmDialog(null, myPanel,
"Please Enter X and Y Values", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
System.out.println("x value: " + xField.getText());
System.out.println("y value: " + yField.getText());
}
}
}
关于java - JOptionPane.showInputDialog 中的多个输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6555040/
我有用于重命名文件的重命名对话框 String renameTo = JOptionPane.showInputDialog(gui, "New Name", currentFile.getName(
我在程序中使用了多个 showInputDialog。当其中一个输入弹出时,它会卡住后台的所有其他窗口,直到收到输入为止,有没有办法让它不卡住其他窗口? 最佳答案 改用非模态 JDialog。请参阅H
我一直在想我的代码有什么问题 String s = JOptionPane.showInputDialog(null,"Enter discount type"); i
所以我有 JOptionPane.showInputDialog() 方法,它返回一个字符串,它是用户输入的值。该对话框有一个确定和一个取消按钮。我如何检查才能知道用户点击的是“确定”还是“取消”?
This question already has answers here: Add Image to JOptionPane
我有一个关于按下 inputDialoguebox 的取消按钮的问题。我之前问过类似的问题,所以如果我似乎重复了一遍,我深表歉意。 我遇到的主要问题是,无论我是否按下取消,我的代码都会执行,并且即使我
如何将自定义文本添加到 JOptionPane.showInputDialog 的按钮? 我知道这个问题JOptionPane showInputDialog with custom buttons
我刚刚开始用 Java 编码,我正在尝试编写一个程序,当我单击 JButton 时运行 chkdsk。我将在这里放置一些代码,以便你们可以帮助我: String disk = JOptionPane.
/image/LrdTN.jpg 我想要这种输入对话框问题是它只接受 int 类型找到了这个 ` String[] options = {"OK"}; int selectedOption = JO
我有一个对象,我们称之为catRancher,他有一个catHerd(ArrayList),在我看来,我有一个列表,其中显示了他所有的猫,并带有一个启动showInputDialog的按钮,我想要的是
public void paint(Graphics g) { myWidth = getSize().width; // get this Applet size myHeight
我想知道 inputdialog 如何返回值,特别是当还有“确定”和“取消”按钮时。有人可以解释一下它是如何实现返回值的吗? 更新: 让我这样说吧。我想创建一个包含 6 个按钮的对话框,每个按钮返回不
String response = javax.swing.JOptionPane.showInputDialog("Enter new database name:"); 如果用户 x 不在选项 P
我可能只是累了。但无论我尝试什么,代码总是会执行。如何让下面的代码仅在字符串包含字符时执行? String input = JOptionPane.showInputDialog(this, "Ent
我以前使用过这个输入对话框,但由于某种原因它使我的程序崩溃。我尝试向输入对话框添加不同的选项,但得到相同的结果 Intelliji 上的错误消息是“进程已完成,退出代码 -805306369” JOp
我想要求用户在showInputDialog中输入整数,但如果输入的是非整数值,则catch将起作用。 谁能引导我走向正确的方向? public static void tryCatch(){
大家好,我的 JOptionPane.showInputDialog 输入字段遇到问题。我遇到的问题是,当选择取消按钮或选择空或明确的确定按钮时,我会收到错误。有什么建议。我第一次尝试解决这个问题,我
我试图在 JOptionPane.showMessageDialog 上放置自定义图标,但收到错误 public static String input (String message) {
今晚我刚刚开始 Java 编程(尽管我是一名长期的 C++ 程序员)。 我正在尝试使用 JOptionPane.showInputDialog() 函数来收集用户输入。 但是,它一直在我的 IDE 下
您好,我是 java 新手,我想问一些有关 JOptionPane.showinput 的问题,以便它只接受字母/数字,如果输入不正确,则会导致错误并需要再次重新输入(在网站上搜索了一些解决方案,但它
我是一名优秀的程序员,十分优秀!