带有下拉菜单和文本输入的MultiPart Java Form

时间:2018-03-23 14:17:05

标签: java swing jtextfield joptionpane

我有一个表单,我想添加一个下拉选择器来选择大约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我想要一个下拉菜单。在哪里选择您想要使用的那个。

1 个答案:

答案 0 :(得分:0)

您可以使用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());
}