JDialog阻止Windows上的父窗口 [英] JDialog blocks parent window on Windows

查看:141
本文介绍了JDialog阻止Windows上的父窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JDialog有一些问题.我在NetBeans中创建了Swing GUI. GUI包含带有按钮,文本字段等的主框架.当我单击下一步"按钮时,将显示JDialog(在NetBeans的其他组件"部分中创建的aslo). 以下是此JDialog的自定义属性:

I have some problem with JDialog. I have Swing GUI created in NetBeans. GUI contains main frame with buttons, text fields, etc. When I click 'Next' button then JDialog (created aslo in NetBeans, Other Components section) is showing. Below are custom properties for this JDialog:

  • modal = true;
  • resizable = false;
  • 默认关闭操作=丢弃

问题在于,在Windows XP(可能也是7)上,当出现JDialog时,我无法通过最小化父窗体来最小化应用程序.在Ubuntu上,它可以按预期运行,但在Windows上却不能.

The problem is that, on Windows XP (probably 7 too), when JDialog occurs then I can't minimalize application by minimalize parent form. On Ubuntu it is working as expected, but on Windows doesn't.

我查看了 http://docs.oracle.com/javase/tutorial/uiswing/misc/modality.html 这个例子也适用于Ubuntu和Widows.因此,我尝试像在演示中一样手动创建示例JDialog.再次在Ubuntu上可以正常工作,而在Windows上则不能.

I have look into http://docs.oracle.com/javase/tutorial/uiswing/misc/modality.html and this example is working on Ubuntu and Widows as well. So, I tried to create sample JDialog manually as in it demo. And again on Ubuntu is woking, on Windows is not.

有人有什么主意吗?我还没有.

COuld someone have any idea? I have not any already.

在DEMO上运行的大量DEMO,在Windows XP上不运行:

SAmple DEMO, working on Ubuntu, not working on Windows XP:

package javaapplication5;

public class TWs extends javax.swing.JFrame {

    /**
     * Creates new form TWs
     */
    public TWs() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jDialog1 = new javax.swing.JDialog();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        jDialog1.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
        jDialog1.setResizable(false);

        jLabel2.setText("Sample Dialog");

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialog1Layout.createSequentialGroup()
                .addContainerGap(212, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(205, 205, 205))
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addGap(122, 122, 122)
                .addComponent(jLabel2)
                .addContainerGap(160, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("Show dialog");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(136, 136, 136)
                .addComponent(jButton1)
                .addContainerGap(164, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(57, 57, 57)
                .addComponent(jButton1)
                .addContainerGap(213, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        jDialog1.setSize(200,200);
        jDialog1.setVisible(true);
    }                                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TWs.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TWs.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TWs.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TWs.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TWs().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration                   
}

推荐答案

请尝试以下注释

您仅使用此构造函数JDialog(父,标题,模型)

you just use this constructor JDialog(Parent, Title, model)

jDialog1 = new javax.swing.JDialog(this, "Test", false); 

并删除设置modalityType的行.

and remove the line which sets modalityType .

jDialog1.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);

希望对您有所帮助.

(请注意,当最小化JFrame时,子JDialog也将最小化)

(Please note that when you minimize tha JFrame the child JDialog will also get minimized)

这篇关于JDialog阻止Windows上的父窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆