【问题标题】:a joptionpane with a textbox and a button带有文本框和按钮的 joptionpane
【发布时间】:2011-01-05 08:47:33
【问题描述】:

我想要一个带有文本框和按钮的 joptionpane,当点击按钮时执行我自己的功能

【问题讨论】:

  • 什么是“文本框”。我不知道 Swing 中有任何具有该名称的组件。

标签: java swing joptionpane


【解决方案1】:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.life.java.so.questions;

import javax.swing.JOptionPane;

/**
 *
 * @author Jigar
 */
public class InputDialog {
    public static void main(String[] args) {
        String input = JOptionPane.showInputDialog("Enter Input:");
        System.out.println(input);
    }
}

输出:

【讨论】:

    【解决方案2】:

    也许您只想要一个带有 JLabel 或 JTextArea 和 JButton 的模态 JDialog。

    【讨论】:

    • 使用 add(myButton) 或 getContentPane().add(myButton)。它是一个与 JFrame 非常相似的顶级容器。
    猜你喜欢
    • 2012-08-31
    • 2018-05-30
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    • 2015-12-17
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多