我原来问的并没有明确说明我的问题/问题,所以我会更好地解释.我有一个JButton,设置一个JDialog可见.JDialog将WindowListener其设置为在windowDeactivated()事件中不可见,该事件在用户在对话框外单击时触发.按钮ActionListener检查对话框是否为可见,如果为true则隐藏它,如果为false则显示该对话框.
windowDeactivated()只要用户在对话框外单击,就会始终触发是否单击按钮.我遇到的问题是当用户单击按钮关闭对话框时.该对话框由关闭WindowListener,然后ActionListener尝试显示它.
如果windowDeactivated()没有setVisible(false),则对话框仍然打开,但在父窗口后面.我要求的是如何访问里面的点击位置windowDeactivated().如果我知道用户点击了按钮并且windowDeactivated()可以跳过隐藏对话框,那么按钮ActionListener会看到它仍然可见并隐藏它.
public PropertiesButton extends JButton {
private JDialog theWindow;
public PropertiesButton() {
theWindow = new JDialog();
theWindow.setUndecorated(true);
theWindow.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
theWindow.add(new JMenuCheckBoxItem("Something"));
theWindow.addWindowListener(new WindowListener() {
// just an example, need to implement other methods
public void windowDeactivated(WindowEvent e) {
theWindow.setVisible(false);
}
});
this.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (theWindow.isVisible()) {
theWindow.setVisible(false);
} else { …