我是 java swing 新手,有一个问题,但首先让我解释一下我的应用程序是做什么的:
在第一次启动时,我的 java web start 应用程序向用户询问用户名和密码,并将它们与 java 首选项 api 一起存储,然后(以及所有其他启动)它在没有任何 gui 的情况下在后台处理所有内容,除非发生错误
我实际上是如何做到的:
public boolean getLogin() {
JTextField u = new JTextField(5);
u.setText("Username");
JPasswordField p = new JPasswordField(5);
p.setText("example");
p.setEchoChar('*');
JPanel input = new JPanel();
input.setLayout(new BoxLayout(input, BoxLayout.Y_AXIS));
input.add(new JLabel("Please input your credentials"));
input.add(Box.createVerticalStrut(25));
input.add(u);
input.add(Box.createVerticalStrut(10));
input.add(p);
int result = JOptionPane.showConfirmDialog(null, input, "Login", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
id.setCredentials(u.getText(), p.getPassword());
return true;
} else
return false;
}
像魅力一样工作,我唯一的问题是 JOptionPane 有时会出现在所有其他窗口(如 webbrowser、资源管理器等)的后面。JOptionPane/JPanel 是否有解决方案让窗口出现在所有其他窗口之上?还是 JOptionPane/JPanel 是错误的?我不需要“始终在最前面”的解决方案,只是该窗口出现在所有其他窗口之上。
先感谢您!