首页javajdialogJava Swing - 如何将JDialog从MODELESS更改为APPLICATION_MODAL

Java Swing - 如何将JDialog从MODELESS更改为APPLICATION_MODAL

我们想知道如何将JDialog从MODELESS更改为APPLICATION_MODAL。
import java.awt.Cursor;
import java.awt.Dialog.ModalityType;
import java.awt.Dimension;
import java.awt.event.ActionEvent;

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

public class Main {

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setSize(new Dimension(500, 500));

    JDialog dialog = new JDialog(frame, "Export",
        ModalityType.MODELESS);
    dialog.setSize(300, 300);

    JDialog dialog1 = new JDialog(dialog, "Export",
        ModalityType.APPLICATION_MODAL);
    dialog1.setSize(200, 200);

    frame.add(new JButton(new AbstractAction("Dialog") {
      @Override
      public void actionPerformed(ActionEvent e) {
        frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        dialog.setVisible(true);
        dialog1.setVisible(true);
      }
    }));
    frame.setVisible(true);
  }
}