【问题标题】:MultiPart Java Form with drop down and text input带有下拉和文本输入的 MultiPart Java 表单
【发布时间】:2018-09-02 06:02:14
【问题描述】:

我有一个表单,我想添加一个下拉选择器来选择大约 5 种不同的东西。示例 ("us" , "usrelease" , "uk" , "ukrelease") 到目前为止,我已经让用户输入了该文本

    public class Proxy {

public static void main(String[] args) throws Exception , IOException , FileNotFoundException {

    //Start of Dialog Box

    JTextField Server = new JTextField();
    JTextField Amount = new JTextField();
    JTextField Server1 = new JTextField();
    Object[] message = {
            "Server Code", Server,
            "How Many Amount", Amount,
            "How Many Servers", Server1,
    };
    JOptionPane.showConfirmDialog(null, message, "ProxyCreator", JOptionPane.OK_CANCEL_OPTION);

我有object server code 我想要一个下拉菜单。在哪里选择你想使用的那个。

【问题讨论】:

    标签: java swing jtextfield joptionpane


    【解决方案1】:

    你可以使用 JComboBox:

    JComboBox<String> Server = new JComboBox<>(
        new String[] { "us", "usrelease", "uk", "ukrelease" });
    

    您可以从 JComboBox 和 JTextField 实例中访问用户的响应和选择/输入的值:

    final int result = JOptionPane.showConfirmDialog(null, message, "ProxyCreator", JOptionPane.OK_CANCEL_OPTION);
    if (result == JOptionPane.OK_OPTION) {
        System.out.println("Server code: " + Server.getSelectedItem());
        System.out.println("Amount: " + Amount.getText());
    }
    

    【讨论】:

    • @Laws 非常感谢,这很有效,但我如何获得他们选择的文本?现在写它的打印输出javax.swing.JComboBox[,0,19,195x25,invalid,layout=javax.swing.plaf.metal.MetalComboBoxUI$MetalComboBoxLayoutManager,alignmentX=0.0,alignmentY=0.0,border=,flags=328,maximumSize=,minimumSize=,preferredSize=,isEditable=false,lightWeightPopupEnabled=true,maximumRowCount=8,selectedItemReminder=usrelease]
    • 我用有关如何做到这一点的信息更新了我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多