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

keyboard navigation in JTabbedPane incorrect under Windows LaF

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.0, 1.3.0
    • client-libs
    • beta
    • x86
    • windows_nt



      Name: diC59631 Date: 09/22/98


      eapHello,

      I'm using WinNT v4.0, SP3.

      This is a bug that occurs under both JDK v1.2b4.1 and JDK v1.1.6 with
      Swing v1.1b2. There are two problems I've found related to TAB key
      navigation using the JTabbedPane under the Windows LaF. I've attached a
      minimal sample program that illustrates these problems

      As a reference for standard (i.e., correct) Windows tabbed pane behavior
      I would recommend you open MS Word, go under the "Tools" menu and select
      the "Options..." menu item. A two-row tabbed dialog will appear. You
      should use this tabbed dialog as a reference for correct behavior.
      Other (native Windows) tabbed dialogs behave analogously.



      Problem 1
      ---------
      When the JTabbedPane is situated such that there are two (or more) rows
      of tabs and a tab in the bottom-most row has the focus, pressing the
      RIGHT-ARROW (or LEFT-ARROW) key cycles through *ALL* the tabs. This is
      contrary to standard Windows LaF for tabbed panes. The correct behavior
      is to repeatedly cycle through the tabs in the current row only. The
      JTabbedPane, however, continuously repeatedly cycles through *all* the
      tabs -- not just the ones in the bottom-most row.

      Run the sample program and do this:
      1. Change the LaF to Windows.
      2. Click on the tab labeled "Panel 1".
      3. Repeatedly press the RIGHT-ARROW key. Notice how the active panel
      cycles from panel 1 through panel 9 and then back again.

      The correct behavior is for the active panel to repeatedly cycle through
      panels 1 through 4 only -- panels 5 through 9 should *not* be activated.



      Problem 2
      ---------
      Standard Windows behavior requires that the CTRL-TAB key combination
      change the currently active tab in a tabbed pane, regardless of which
      control currently has the focus. The best way to see this is to open
      any Windows dialog that contains a tabbed pane (such as the MS Word
      "Tools | Options..." dialog). Pressing the CTRL-TAB key combination
      cycles through all the tabs. The JTabbedPane seems to treat the
      CTRL-TAB as a normal TAB. This is incorrect under the Windows LaF.


      Let me know if any of this is not clear. You can reach me at
      602-607-4995.

      Regards.


      import com.sun.java.swing.*;
      import java.awt.event.*;
      import java.awt.*;


      class Tester {
         public static void main(String[] args) {
            final JFrame f = new JFrame();
            final JTabbedPane tabbedPane = new JTabbedPane();
            final JPanel panel1 = new JPanel(false),
                              panel2 = new JPanel(false),
                              panel3 = new JPanel(false),
                              panel4 = new JPanel(false),
                              panel5 = new JPanel(false),
                              panel6 = new JPanel(false),
                              panel7 = new JPanel(false),
                              panel8 = new JPanel(false),
                              panel9 = new JPanel(false);
                              
            // WindowListener for cosing progam.
            f.addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent evt) {
                  evt.getWindow().dispose();
                  System.exit(0);
               }
            });

            tabbedPane.add("Panel 1", panel1);
            tabbedPane.add("Panel 2", panel2);
            tabbedPane.add("Panel 3", panel3);
            tabbedPane.add("Panel 4", panel4);
            tabbedPane.add("Panel 5", panel5);
            tabbedPane.add("Panel 6", panel6);
            tabbedPane.add("Panel 7", panel7);
            tabbedPane.add("Panel 8", panel8);
            tabbedPane.add("Panel 9", panel9);
            
            f.getContentPane().add(tabbedPane, BorderLayout.CENTER);

            //--------------------
            // The remaining code simply allows for a change in the LaF....
            //--------------------
            JPanel LaFPanel = new JPanel();

            final JButton windowsLaF = new JButton("Windows"),
                          motifLaF = new JButton("Motif"),
                          metalLaF = new JButton("Metal");

            LaFPanel.add(windowsLaF);
            LaFPanel.add(motifLaF);
            LaFPanel.add(metalLaF);

            ActionListener LaFListener = new ActionListener() {
               public void actionPerformed(ActionEvent evt) {
                  Object src = evt.getSource();

                  try {
                     if(src == windowsLaF)
                        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                     else if(src == motifLaF)
             UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
                     else
             UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");

                     SwingUtilities.updateComponentTreeUI(f);
                  }
                  catch(Exception e) {
                     System.err.println("*** ERROR IN CHANGING LAF: " + e);
                  }
               }
            };

            windowsLaF.addActionListener(LaFListener);
            motifLaF.addActionListener(LaFListener);
            metalLaF.addActionListener(LaFListener);

            f.getContentPane().add(LaFPanel, BorderLayout.SOUTH);
            f.setResizable(false);
            f.setBounds(40, 40, 330, 200);
            f.setVisible(true);
         }
      }
      (Review ID: 39192)
      ======================================================================

            amfowler Anne Fowler (Inactive)
            dindrigo Daniel Indrigo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: