JDK-4840682 : Modal dialog covers another modal dialog on RedHat Linux
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.1_06
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux_redhat_6.2
  • CPU: x86
  • Submitted: 2003-04-01
  • Updated: 2005-05-05
  • Resolved: 2005-05-05
Related Reports
Duplicate :  
Description
OS: Red Hat Linux 6.2J Second Edition
Desktop Environment: GNOME
J2SE version: 1.3.1_06

Problem: 
  - Modal dialog covers another modal dialog
  - Focus of modal dialog can be shifted

In sample program, 2 dialogs(both modal) will be created by pressing buttons. 
By following procedure below, first dialog covers second dialog. The second 
dialog, which is created after the first dialog, should not be covered by the 
first dialog. Also by clicking on the first dialog or parent JFrame, the focus 
of the second dialog will be shifted to the first dialog or parent JFrame. The 
fucus of the second dialog should not be shifted to the first dialog or parent 
JFrame.
Behavior on Windows and Solaris seems correct.

Procedure to reproduce the problem:
1) run the sample program:  %> java TestModal 
2) Click [Open] button
3) First JDialog(modal) comes up
4) Click [Go] button
5) Second JDialog(modal) comes up
6) Click parent JFrame
7) First JDialog(modal) covers second JDialog
8) Also clicking the first dialog or first dialog, focus can be shifted

Sample programs:
 1. TestModal.java
 2. JDialogOne.java
 3. JDialogTwo.java

=== TestModal.java =====================================================
import java.awt.Dimension;
import java.awt.Toolkit;

public class TestModal extends javax.swing.JFrame {

    private javax.swing.JButton jButton1;

    public TestModal() {
        super("1st JFrame");
        initComponents();
    }

    private void initComponents() {
        jButton1 = new javax.swing.JButton();

        getContentPane().setLayout(new java.awt.GridLayout(1, 0));

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        jButton1.setText("Open");
        jButton1.setName("Open");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        pack();
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        JDialogOne jDialogOne = JDialogOne.open(this);
    }

    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }

    public static void main(String args[]) {
        TestModal testModal = new TestModal();

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        testModal.setLocation(
            screenSize.width / 2 - testModal.getWidth() / 2,
            screenSize.height / 2 - testModal.getHeight() / 2);
        testModal.show();
    }
}

========================================================================

==== JDialogOne.java ===================================================
import java.awt.Component;
import javax.swing.*;
import java.awt.Toolkit;

public class JDialogOne extends javax.swing.JDialog {

    private static JDialogOne jDialogOne = null;

    private static JFrame owner = null;

    private javax.swing.JButton jButton2;

    private javax.swing.JButton jButton1;


    public JDialogOne(JFrame parent) {
        super(parent);
        initComponents();
    }


    private void initComponents() {
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setTitle("2nd JDialog");
        setModal(true);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

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

        getContentPane().add(jButton1, java.awt.BorderLayout.NORTH);

        jButton2.setText("Back");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        getContentPane().add(jButton2, java.awt.BorderLayout.SOUTH);

        pack();
        setResizable(false);

    }


    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        close();
    }


    private void closeDialog(java.awt.event.WindowEvent evt) {
        close();
    }


    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        JDialogTwo jDialogTwo = JDialogTwo.open(owner);
    }


    private void close(){
        setVisible(false);
    }


    public static JDialogOne open(Component parent){

        owner = (JFrame)parent;

        if(jDialogOne == null){
            jDialogOne = new JDialogOne(owner);
        }

        jDialogOne.setBounds(300, 300, 200, 200);
        jDialogOne.setVisible(true);
        return jDialogOne;
    }
}
========================================================================

==== JDialogTwo.java ===================================================
import java.awt.Component;
import javax.swing.*;
import java.awt.Toolkit;

public class JDialogTwo extends javax.swing.JDialog {

    private static JDialogTwo jDialogTwo = null;

    private static JFrame owner = null;

    private javax.swing.JButton jButton2;


    public JDialogTwo(JFrame parent) {
        super(parent);
        initComponents();
    }


    private void initComponents() {
        jButton2 = new javax.swing.JButton();

        setTitle("3rd JDialog");
        setModal(true);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        jButton2.setToolTipText("3rd");
        jButton2.setText("Back");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        getContentPane().add(jButton2, java.awt.BorderLayout.CENTER);

        pack();
        setResizable(false);

    }


    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        close();
    }


    private void closeDialog(java.awt.event.WindowEvent evt) {
        close();
    }


    private void close(){
        setVisible(false);
    }


    public static JDialogTwo open(Component parent){

        owner = (JFrame)parent;

        if(jDialogTwo == null){
            jDialogTwo = new JDialogTwo(owner);
        }

        jDialogTwo.setBounds(350, 350, 100, 100);
        jDialogTwo.setVisible(true);
        return jDialogTwo;
    }
}
========================================================================

Comments
EVALUATION Related to 4255200? ###@###.### 2003-04-01 Name: osR10079 Date: 04/02/2003 This is not mantis or hopper regression (it's reproducible with 1.3.1) We need to verify if fix for 4255200 will fix this problem. ###@###.### 2003-04-02 ====================================================================== The fix for 4080029 (modality umbrella bug), which fixes 4255200, fixes this bug also. So I'm marking this as duplicate of 4255200. ###@###.### 2005-05-05 07:51:43 GMT
05-05-2005