Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4624207
Votes 0
Synopsis JTabbedPane mnemonics don't work from outside the tabbed pane
Category java:classes_swing
Reported Against 1.4.1 , merlin-beta3
Release Fixed 1.5(tiger)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs 4898787
Submit Date 16-JAN-2002
Description




FULL PRODUCT VERSION :
java version "1.4.0-beta3"

Java(TM) 2 Runtime Environment, Standard Edition (build
1.4.0-beta3-b84)

Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed
mode)


FULL OPERATING SYSTEM VERSION :
Windows Millennium [Version 4.90.3000]




A DESCRIPTION OF THE PROBLEM :
Mnemonics on JTabbedPane tabs are now supported.
However, it seems that they only work when
the tabbed pane or one of its children has
the focus.

Why I think this is wrong:
1. In a frame/dialog that contains a tabbed pane
   there might be other components that may have
   the focus and the user might wish to transfer
   the focus from one of those components (text field,
   button, ...) to the tabbed pane or a specific
   tab in the tabbed pane using the keyboard.
   Certainly this would be useful.
2. Tab mnemonics are visible on the screen
   (the character is underlined) and the user expects
   visible mnemonics to work (just like they do
   on buttons or menus), no matter where the focus is.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached test case.

Try to activate the tab mnemonics by pressing
ALT+T or ALT+S while the 'Name' text field
or the 'OK' button has the focus. It won't work.


EXPECTED VERSUS ACTUAL BEHAVIOR :
Using the mnemonics associated with one of the tabs
should result in the specific tab being selected
even if the focus wasn't in the tabbed pane before.
With the current implementation, this isn't the case.


This bug can be reproduced always.

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

public class TestDialog extends JDialog {
  private JPanel pnl;
  private JPanel namePnl;
  private JLabel nameLbl;
  private JTextField nameTxtFld;
  private JTabbedPane tbbdPn;
  private JPanel dlgButPnl;
  private JButton okBut;
  
  public TestDialog() {
    super((Frame) null, "Title", true);
  
    pnl = new JPanel();
    pnl.setBorder(new EmptyBorder(9, 6, 5, 5));
    pnl.setLayout(new GridBagLayout());
    
      namePnl = new JPanel();
      namePnl.setLayout(new GridBagLayout());
      
        nameLbl = new JLabel("Name:");
        nameLbl.setDisplayedMnemonic('m');
        namePnl.add(nameLbl, new GridBagConstraints(
          GridBagConstraints.RELATIVE, 0, 1, 1, 0, 0,
          GridBagConstraints.CENTER,
GridBagConstraints.NONE,
          new Insets(0, 0, 0, 0), 0, 0));
          
        namePnl.add(Box.createHorizontalStrut(6), new
GridBagConstraints(
          GridBagConstraints.RELATIVE, 0, 1, 1, 0, 0,
          GridBagConstraints.CENTER,
GridBagConstraints.NONE,
          new Insets(0, 0, 0, 0), 0, 0));
          
        nameTxtFld = new JTextField();
        nameLbl.setLabelFor(nameTxtFld);
        namePnl.add(nameTxtFld, new GridBagConstraints(
          GridBagConstraints.RELATIVE, 0, 1, 1, 1, 0,
          GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL,
          new Insets(0, 0, 0, 0), 0, 0));
      
      pnl.add(namePnl, new GridBagConstraints(
        0, GridBagConstraints.RELATIVE, 1, 1, 1, 0,
        GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL,
        new Insets(0, 9, 0, 9), 0, 0));
        
      JSeparator sep = new JSeparator();
      pnl.add(sep, new GridBagConstraints(
        0, GridBagConstraints.RELATIVE, 1, 1, 1, 0,
        GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL,
        new Insets(7, 9, 3, 9), 0, 0));
        
      tbbdPn = new JTabbedPane();
      
        tbbdPn.addTab("Tab 1", new JTextArea("Dingo"));
        tbbdPn.setMnemonicAt(0, KeyEvent.VK_T);
        
        tbbdPn.addTab("Tab 2", new JTextArea("Manga"));
        tbbdPn.setMnemonicAt(1, KeyEvent.VK_B);
        
      pnl.add(tbbdPn, new GridBagConstraints(
        0, GridBagConstraints.RELATIVE, 1, 1, 1, 1,
        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
        new Insets(0, 0, 0, 1), 0, 0));
        
      pnl.add(Box.createVerticalStrut(6), new
GridBagConstraints(
        0, GridBagConstraints.RELATIVE, 1, 1, 0, 0,
        GridBagConstraints.CENTER, GridBagConstraints.NONE,
        new Insets(0, 0, 0, 0), 0, 0));
      
      dlgButPnl = new JPanel();
      dlgButPnl.setLayout(new GridLayout(1, 0, 5, 0));
    
        okBut = new JButton("OK");
        okBut.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              setVisible(false);
            }
          });
        getRootPane().setDefaultButton(okBut);
        dlgButPnl.add(okBut);
          
      pnl.add(dlgButPnl, new GridBagConstraints(
        0, GridBagConstraints.RELATIVE, 1, 1, 1, 0,
        GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL,
        new Insets(0, 0, 0, 0), 0, 0));
        
    setContentPane(pnl);
    
    setSize(new Dimension(384, 496));
  }
    
  public static void main(String[] args) {
    new TestDialog().show();
  }
}

---------- END SOURCE ----------
(Review ID: 137758) 
======================================================================
Work Around
N/A
Evaluation
Josh, I had asked Lynn about this when he had put the code in and he never adequately answered why they behave like this (they are registered WHEN_ANSCESTOR vs WHEN_IN_FOCUSED_WINDOW). You should ping him again on this.
  xxxxx@xxxxx   2002-01-16

This needs to be changed to WHEN_IN_FOCUSED_WINDOW.
  xxxxx@xxxxx   2002-06-13
Comments
  
  Include a link with my name & email   

Submitted On 16-JAN-2002
snebeling
In the above report, the line
"Try to activate the tab mnemonics by pressing ALT+T or 
ALT+S" should read
"Try to activate the tab mnemonics by pressing ALT+T or 
ALT+B".



PLEASE NOTE: JDK6 is formerly known as Project Mustang