首页 > 解决方案 > 模态 JDialog 隐藏在 macOS Big Sur 上的主框架后面

问题描述

单击框架上的某个位置时,模态对话框隐藏在主框架后面。

主框架被阻止(正确),只有通过单击主框架标题栏才能将对话框带回前面。

在 Mac mini(2018,Intel Core i5,macOS Big Sur 11.1)上测试

使用 AdoptOpenJDK 8(HotSpot 和 OpenJ9)、AdoptOpenJDK 11、AdoptOpenJDK 15、Amazon Corretto 15 和 Oracle JDK 16 进行了测试。

其他人可以重现这个问题吗?

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;

public class Test {
  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().setLayout(new FlowLayout());
    JButton button = new JButton("Open modal dialog");
    button.addActionListener(e -> actionOpenDialog(frame));
    frame.getContentPane().add(button);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(600, 450);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }

  private static void actionOpenDialog(JFrame frame) {
    JDialog dialog = new JDialog(/* parent */ frame, /* modal */ true);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.setSize(300, 200);
    dialog.setLocationRelativeTo(dialog.getParent());
    dialog.setVisible(true);
  }
}

在此处输入图像描述

错误报告:JDK-8263801

标签: javamacosswingmodal-dialogmacos-big-sur

解决方案


推荐阅读