1
即使GUI移动到不同位置,我也希望在应用程序前面有警告showConfirmDialog窗口,如果我不移动application并按下'关闭ALT + X'按钮,它会正常工作,但如果我将应用程序移动到第二个屏幕,警告showConfirmDialog窗口停留在旧位置,如何随GUI一起移动警告窗口,请给我指示,谢谢。将JOptionPane的showConfirmDialog与Java应用程序一起移动
关闭ALT + X键
//close window button
JButton btnCloseWindow = new JButton("Close ALT+X");
btnCloseWindow.setMnemonic('x');
btnCloseWindow.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
int result = JOptionPane.showConfirmDialog(frame, "Are you sure you want to close the application?", "Please Confirm",JOptionPane.YES_NO_OPTION);
//find the position of GUI and set the value
//dialog.setLocation(10, 20);
if (result == JOptionPane.YES_OPTION)
System.exit(0);
}
});
到目前为止,我试图设置的GUI showConfirmDialog的位置的位置中心,但没有奏效。
Thanks @Hovercraft当我将btnCloseWindow更改为frmViperManufacturingRecord时,警告窗口即将到来。 'int result = JOptionPane.showConfirmDialog(frmViperManufacturingRecord,“你确定要关闭应用程序?”,“请确认”,JOptionPane.YES_NO_OPTION);'非常感谢你的时间和帮助 – 2014-12-02 13:22:53