Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4840682

Modal dialog covers another modal dialog on RedHat Linux

    • x86
    • linux_redhat_6.2

      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;
          }
      }
      ========================================================================

            art Artem Ananiev (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: