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

MToolkit:Focus is lost and no further response to key press (keys TAB/Space)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 6u2
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • CPU:
      x86, sparc
    • OS:
      linux, solaris_2.5.1

      Description

      OPERATING SYSTEM(S):
      --------------------
      Linux (Redhat/Suse)
       

      FULL JDK VERSION(S):
      -------------------
      java version "1.6.0_02"
      Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
      Java HotSpot(TM) Server VM (build 1.6.0_02-b05, mixed mode)


      DESCRIPTION:
      ------------

      PROBLEM DESCRIPTION

      Focus is lost using MToolkit but using XToolkit focus is not lost. The same problem is seen in all linux supported LookAndFeel.

      Steps to Recreate:
      1. Compile our test case
         
      2. Launch test case with MAWT and avoid using mouse once application is
         launched
         
         $ AWT_TOOLKIT=MToolkit java dialogs_main

      3. Press TAB to reach "Show it!" button (Please do not use mouse to
         bring focus at button)

      4. Now press "SpaceBar" to select/click the button, it will display a
         message dialog box.

      5. Again press "spaceBar" to select "ok" button of the dialog box
         displayed. Notice focus comes back to the "Show it!" button of
         Tabbed Frame.
         
      6. Keep repeating steps 4 and 5

      Observed result:
         Focus is lost. Focus seems to be in "show it!" button but now its
         not responding to the keyboard press of "SpaceBar/TAB".

      Notes:
         Problem does not always occur. Frequency is about 4 out of 5 times.
         Problem does not occur on XAWT Toolkit.


      TEST CASE:

      import javax.swing.*;
      import java.beans.*; // Property change stuff
      import java.awt.*;
      import javax.swing.border.Border;
      import java.awt.event.*;

      class Dialogs extends JPanel {
          JLabel label;
          ImageIcon icon = new ImageIcon("images/middle.gif");
          JFrame frame;
          String simpleDialogDesc = "Some simple message dialogs";
          String iconDesc = "A JOptionPane has its choice of icons";
          String moreDialogDesc = "Some more dialogs";

          public Dialogs(JFrame frame) {
              this.frame = frame;

              // create the components
              JPanel frequentPanel = createSimpleDialogBox();

              label = new JLabel("Click the \"Show it!\" button"
                                 + " to bring up the selected dialog.",
                                 JLabel.CENTER);

              // lay them out
              Border padding = BorderFactory.createEmptyBorder(20, 20, 5,
                                                               20);

              MyJTabbedPane tabbedPane = new MyJTabbedPane();
              tabbedPane.addTab("Simple Modal Dialogs", null, frequentPanel,
                                simpleDialogDesc, KeyEvent.VK_S, 0);
              setLayout(new BorderLayout());
              add(tabbedPane, BorderLayout.CENTER);
              add(label, BorderLayout.SOUTH);
              label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10,
                                                              10));
          }

          void setLabel(String newText) {
              label.setText(newText);
          }

          private JPanel createSimpleDialogBox() {
              final int numButtons = 1;
              JRadioButton radioButtons =null;
              final ButtonGroup group = new ButtonGroup();

              JButton showItButton = null;

              final String defaultMessageCommand = "default";
              final String yesNoCommand = "yesno";
              final String yeahNahCommand = "yeahnah";
              final String yncCommand = "ync";

              radioButtons = new JRadioButton("OK (in the L&F's words)");
              radioButtons.setActionCommand(defaultMessageCommand);
              radioButtons.setMnemonic(KeyEvent.VK_O);

              group.add(radioButtons);

              radioButtons.setSelected(true);

              showItButton = new JButton("Show it!");
              showItButton.setMnemonic(KeyEvent.VK_H);
              showItButton.addActionListener(new ActionListener()
                  {
                      public void actionPerformed(ActionEvent e) {
                          String command =
                              group.getSelection().getActionCommand();

                          // ok dialog
                          if (command == defaultMessageCommand) {
                              JOptionPane.showMessageDialog(frame,
                                                            "Hello...");
                          }
                          return;
                      }
                  });

              return createPane(simpleDialogDesc + ":", radioButtons,
                                showItButton);
          }


          private JPanel createPane(String description,
                                    JRadioButton radioButtons,
                                    JButton showButton) {

              JPanel box = new JPanel();
              JLabel label = new JLabel(description);

              box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));
              box.add(label);

              box.add(radioButtons);


              JPanel pane = new JPanel();
              pane.setLayout(new BorderLayout());
              pane.add(box, BorderLayout.NORTH);
              pane.add(showButton, BorderLayout.SOUTH);
              return pane;
          }
      }

      class MyJTabbedPane extends JTabbedPane {
          public void addTab(String title, Icon icon, Component component,
                             String tip, int mnemonic, int index) {
              this.add(component, index);
              this.setTitleAt(index, title);
              this.setMnemonicAt(index, mnemonic);
              this.setToolTipTextAt(index, tip);
          }
      }

      class dialogs_main {
          public static void main(String []args) {
              JFrame frame = new JFrame("Dialogs Test");
              Container c = frame.getContentPane();

              c.add(new Dialogs(frame));

              frame.pack();
              frame.setVisible(true);
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                elarsen Erik Larsen (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: