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

JSplitPane prevents focus traversal keys other than default from being used

XMLWordPrintable

    • Fix Understood
    • x86
    • windows_2000

      Name: jk109818 Date: 05/09/2003


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

      FULL OS VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      In our application, we need to provide focus traversal keys in addition to Tab/Shift tab. We are doing this by modifying the default traversal keys on the keyboard focus manager. This worked fine until we made use of JSplitPane. The JSplitPane component prevents any keys other than the initial default traversal keys from working.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) javac SplitPaneBug.java
      2) java SplitPaneBug

      Note the output produced. Before the button is added to the JPanel, there are four keycodes in the focus forward traversal set. After added to the JPanel, still four. But after adding to the JSplitPane, there is only one. Also note that for example purposes, the JScrollPane has the same behavior as JPanel.

      Now click the button labeled "Button1". Note the output produced has the four keycodes. Now press Alt-Page down. Focus is transferred to the button labeled Button2. Press Alt-Page down again. Nothing happens. This button does not have the traversal.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      I had expected that the button have the forward traversal keys I specified, regardless of the container to which it was added.
      The button did not have the traversal keys i specified.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No error was displayed.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.*;

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

      public class SplitPaneBug {
          static {
          // Get the current forward traversal keys for the application
          Set set = new HashSet(
          KeyboardFocusManager.getCurrentKeyboardFocusManager()
             .getDefaultFocusTraversalKeys(
          KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));

          // Add in Alt Page down
          set.add(KeyStroke.getKeyStroke("alt PAGE_DOWN"));

          // Make this the new set of forward traversal keys
          KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .setDefaultFocusTraversalKeys(
          KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set);
          }

          public static void main(String[] s) {
          JFrame frame = new JFrame("SplitPane Bug");

          FlowLayout fl = new FlowLayout( FlowLayout.LEFT, 0, 0 );
          JPanel topPanel = new JPanel( fl );

          JSplitPane bottomSplit = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT );

          JPanel leftPanel = new JPanel( new GridLayout( 0, 1 ) );
          JPanel rightPanel = new JPanel();

          JButton b1 = new JButton( "Button1" );
          JButton b2 = new JButton( "Button2" );

          ActionListener al = new ActionListener() {
              public void actionPerformed(ActionEvent e) {
              JButton button = (JButton) e.getSource();
              System.out.println( button.getFocusTraversalKeys(
                  KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS ) );
              }
          };

          b1.addActionListener( al );
          b2.addActionListener( al );

          JPanel all = new JPanel( new BorderLayout() );

          topPanel.add(b1);
          System.out.println( "before add to panel: "
              + b2.getFocusTraversalKeys(
              KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS ) );
          leftPanel.add(b2);
          System.out.println( "after add to panel: "
              + b2.getFocusTraversalKeys(
              KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS ) );
          bottomSplit.add(leftPanel);
          System.out.println( "after add to split: "
              + b2.getFocusTraversalKeys(
              KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS ) );
          bottomSplit.add(rightPanel);

          /* Remove this line for work around
          Set set = new HashSet(
          KeyboardFocusManager.getCurrentKeyboardFocusManager()
              .getDefaultFocusTraversalKeys(
          KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
              b2.setFocusTraversalKeys(
              KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set );
          /* */

          all.add( topPanel, BorderLayout.NORTH );
          all.add( bottomSplit, BorderLayout.CENTER );

          // Not displayed
          JButton b3 = new JButton( "Button3" );
          JScrollPane scroll = new JScrollPane(b3);
          System.out.println( "after add to scroll: "
              + b3.getFocusTraversalKeys(
              KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS ) );

          all.setPreferredSize( new Dimension( 300, 200 ) );
          frame.getContentPane().add( all );
          frame.pack();
          frame.setVisible(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Workaround is to explicitly add traversal keys to the components within the split pane.
      (Review ID: 184511)
      ======================================================================

            Unassigned Unassigned
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: