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

Keyboard-lock in swing program on Linux box

    Details

    • Subcomponent:
    • Introduced In Version:
      5.0
    • CPU:
      x86
    • OS:
      solaris_2.5.1

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.6.0"
        Java(TM) SE Runtime Environment (build 1.6.0-b105)
        Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

        java version "1.5.0_10"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
        Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        RHEL 4 - Linux 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686 i686 i386 GNU/Linux
        Red Flag 5 - Linux 2.6.9-11.19AXsmp #1 SMP Fri Aug 5 05:28:32 EDT 2005 i686 i686 i386 GNU/Linux

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        gnome-desktop-2.8.0-5
        kdebase-3.2.1-62AX.i386. kdelibs-3.2.1-44AX.i386.


        A DESCRIPTION OF THE PROBLEM :
        Run some swing program, keyboard is locked after some opterations, then it don't respond any key event.

        Here is a demo program, no multi-thread, no event-dispatching thread problem. It always can be reproduced on RHEL 4 and Red Flag 5.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the program I post, follow the steps in "about":

        1 - press Alt+N to navigate next, and don't release keys untill there are no more next page, then try Alt+B to navigate back and also don't release keys untill page 0, repeat Alt+N and Alt+B again and again, keyboard will be locked during navigating.

        2 - press Alt+A in main window, it will popup an about dialog, then press down space key and don't release, the about dialog will be closed and opened again and again, keyboard will be locked sooner or later.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Keyboard should not be locked!

        ACTUAL -
        The keyboard focus is there, but it don't respond any key event in all component and window, except in JPasswordField.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        package test;

        import java.awt.*;
        import java.awt.event.*;
        import javax.swing.*;
        import java.util.*;

        public class KeyLock extends JFrame {
          JPanel contentPanel = new JPanel();
          JPanel wizardToolPan = new JPanel();
          JButton btnBack = new JButton("Back");
          JButton btnNext = new JButton("Next");
          JButton btnAbout = new JButton("About");
          public static final String aboutMsg =
                  "<html> This program will help to find keyboard lock problems, two way to reproduce:<br><br>" +
                  "1 - press Alt+N to navigate next, and don't release keys untill there are no more next page, <br>" +
                  "then try Alt+B to navigate back and also don't release keys untill page 0,<br>" +
                  "repeat Alt+N and Alt+B again and again, keyboard will be locked during navigating. <br><br>" +
                  "2 - press Alt+A in main window, it will popup an about dialog,<br>" +
                  "then press down space key and don't release, <br>" +
                  "the about dialog will be closed and opened again and again,<br>" +
                  "keyboard will be locked sooner or later." +
                  "</html>";

          public KeyLock() {
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
            this.setTitle("Keyboard lock test");

            getContentPane().setLayout(new BorderLayout());
            btnBack.setMnemonic('B');
            btnBack.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                KeyLock.this.goBack(e);
              }
            });

            btnNext.setMnemonic('N');
            btnNext.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                KeyLock.this.goNext(e);
              }
            });

            btnAbout.setMnemonic('A');
            btnAbout.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(KeyLock.this, aboutMsg, "About", JOptionPane.INFORMATION_MESSAGE);
              }
            });

            contentPanel.setLayout(new BorderLayout());
            contentPanel.setPreferredSize(new Dimension(400, 250));
            contentPanel.setMinimumSize(new Dimension(400, 250));

            wizardToolPan.setLayout(new FlowLayout());
            wizardToolPan.add(btnBack);
            wizardToolPan.add(btnNext);
            wizardToolPan.add(btnAbout);

            this.getContentPane().add(contentPanel, java.awt.BorderLayout.CENTER);
            this.getContentPane().add(wizardToolPan, java.awt.BorderLayout.SOUTH);

            this.setSize(400, 300);
            this.createContentPanels();
            this.showCurrent();
          }

          private Vector<JPanel> slides = new Vector<JPanel>();
          private int current = 0;

          private void createContentPanels() {
            for (int j = 0; j < 20; ++j) {
              JPanel p = new JPanel(new FlowLayout());
              p.add(new JLabel("Page: " + j));
              p.add(new JTextField("Page: " + j + ", input something here", 20));
              p.add(new JTextField("Page: " + j + ", input something here", 20));
              p.add(new JTextField("Page: " + j + ", input something here", 20));
              p.add(new JLabel("Input something in password box:"));
              p.add(new JPasswordField(20));
              p.add(new JCheckBox("Try click here, focus will be here."));
              p.add(new JRadioButton("Try click here, focus will be here."));

              slides.add(p);
            }
          }

          public void showCurrent() {
            if (current < 0 || current >= slides.size())
              return;

            JPanel p = slides.get(current);
            this.contentPanel.add(p, java.awt.BorderLayout.CENTER);
            this.pack();

            Component[] comps = p.getComponents();
            if (comps.length > 0) {
              comps[0].requestFocus(); // try delete this line
            }
            this.repaint();
          }

          public void goNext(ActionEvent e) {
            if (current + 1 >= slides.size())
              return;
            this.contentPanel.remove(slides.get(current));
            current++;
            sleep(100);
            this.showCurrent();
          }

          public void goBack(ActionEvent e) {
            if (current <= 0)
              return;
            this.contentPanel.remove(slides.get(current));
            current--;
            sleep(100);
            this.showCurrent();
          }

          public static void sleep(int millis) {
            try {
              Thread.sleep(millis);
            } catch (Exception e) {
              e.printStackTrace();
            }
          }

          public static void main(String[] args) {
            KeyLock wizard = new KeyLock();
            wizard.setVisible(true);
          }
        }

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

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  pardesha Pardeep Sharma
                  Reporter:
                  ndcosta Nelson Dcosta
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: