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