我需要使用JOptionPane以不同的方式获取输入。具体来说,我需要一个下拉菜单以及默认的输入文本字段,以将它们都显示在同一JOptionPane中。这可以实现吗?如果可以,怎么办?
答案 0 :(得分:0)
如果您的pane
中需要其他组件,则可以尝试实现以下内容:
JTextField firstName = new JTextField();
JTextField lastName = new JTextField();
JPasswordField password = new JPasswordField();
final JComponent[] inputs = new JComponent[] {
new JLabel("First"),
firstName,
new JLabel("Last"),
lastName,
new JLabel("Password"),
password
};
int result = JOptionPane.showConfirmDialog(null, inputs, "My custom dialog", JOptionPane.PLAIN_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
System.out.println("You entered " +
firstName.getText() + ", " +
lastName.getText() + ", " +
password.getText());
} else {
System.out.println("User canceled / closed the dialog, result = " + result);
}