JDialog 在 Java 中的设置模式类型为 MODELESS 时会发生什么


Modeless 对话框在屏幕上,并且可以供用户使用。以下是使用设置模式类型 MODELESS 的 JDialog 的示例

示例

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 SwingDemo {
   public static void main(String[] args) {
      JFrame frame = new JFrame();
      frame.setSize(new Dimension(600, 400));
      JDialog dialog = new JDialog(frame, "New",ModalityType.MODELESS);
      dialog.setSize(300, 300);
      frame.add(new JButton(new AbstractAction("Click to generate") {
         @Override
         public void actionPerformed(ActionEvent e) {
            frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            dialog.setVisible(true);
         }
      }));
      frame.setVisible(true);
   }
}

输出

现在,单击它以生成新的会话。你随时可以关闭它,因为它是 Modeless

更新于: 2019 年 7 月 30 日

84 次浏览

开始你的 事业

通过完成课程获得认证

开始
广告
© . All rights reserved.