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

Modal dialogs under Linux are broken

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 5.0
    • client-libs
    • Cause Known
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux ronny 2.6.15-1-686 #2 Thu Feb 2 18:29:01 UTC 2006 i686 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      I am developing a professional Java application on Linux and noticed two problems with modal dialogs when using Linux/Java-1.5.x:
      - sometimes the dialogs just don't disappear
      - sometimes the parent does not get back the focus

      I created a small test program that demonstrates both problems.
      I could not reproduce the bug with Linux/Java-1.4.2 or with any Windows/Java version. But I noticed that Linux/Mustang is also affected.

      I consider this problems showstoppers that prevent us seriously running our Java application on Linux.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try out the test case in Linux with Java > 1.4.2.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect to see a lot of JDialogs appear and disappear and that the parent window gets back the window focus thereafter.
      ACTUAL -
      I see a lot of JDialogs appear and sometimes NOT disappear and saw that the parent window sometimes does NOT get back the window focus thereafter.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.event.*;
      import javax.swing.*;

      public class ModalDialogTest extends JFrame {
          
          private boolean dialogShown = false;
          
          public ModalDialogTest() {
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              
              final JDialog[] dialogs = new JDialog[30];
              for (int i = 0; i < 30; i++) {
                  dialogs[i] = getNewDialog("Dialog " + i);
              }
              
              final JButton startButton = new JButton("Start");
              startButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      startButton.setEnabled(false);
                      for (int i = 0; i < dialogs.length; i++) {
                          JDialog dialog = dialogs[i];
                          dialog.setLocation(i * 5, i * 5);
                          showAndHideDialog(dialog);
                      }
                      startButton.setEnabled(true);
                  }
              });
              getContentPane().add(startButton);
              
              setSize(200, 50);
              setLocationRelativeTo(null);
          }
          
          public static void main(String[] args) {
              ModalDialogTest myTest = new ModalDialogTest();
              myTest.setVisible(true);
          }
          
          private void showAndHideDialog(final JDialog dialog) {
              Timer timer = new Timer(10, new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      if (dialogShown) {
                          while (!dialog.isVisible()) {
                              try {
                                  Thread.sleep(10);
                              } catch (InterruptedException ex) {
                                  ex.printStackTrace();
                              }
                          }
                          dialog.setVisible(false);
                      }
                      dialogShown = false;
                  }
              });
              dialogShown = true;
              timer.start();
              dialog.setVisible(true);
              timer.stop();
          }
          
          private JDialog getNewDialog(String text) {
              JDialog dialog = new JDialog(this, text, true);
              dialog.getContentPane().add(new JLabel(
                      "<html>This might be any other component<br>" +
                      "which is large enough to demonstrate<br>" +
                      "the dialogs height."));
              dialog.pack();
              return dialog;
          }
      }

      ---------- END SOURCE ----------

            dav Andrei Dmitriev (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: