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

JTable doesn't get focus the first time its accelerator is typed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • solaris_9, 1.3.1
    • client-libs
    • None
    • beta
    • x86, sparc
    • solaris_9

      Below is a very simple program that illustrates the problem. It puts up a JFrame with a JLabel whose accelerator should put the focus in a JTable. The JTable has a FocusListener that prints out when the table gains or loses focus. If you compile and run this test program, typing Alt+l should put the focus in the table, and "TABLE GAINED FOCUS" should get printed to stdout. This doesn't happen until the second time you type Alt+l.

      NOTE: This bug was originally encountered in the Solaris Management Console System Information tool. Also, I'm not sure if this bug is truly Solaris specific. I encountered it on SunOS 5.9 s81_33 using JDK 1.3.1-beta-b15


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

      public class LabelTableTest {

          public static void main(String argv[]) {

              LabelTableTest myTest = new LabelTableTest();

          }

          public LabelTableTest () {

              JFrame frame = new JFrame();
              JPanel panel = new LabelTablePanel();
              frame.getContentPane().add(panel);

              frame.pack();
              frame.show();

          } // constructor

          /**
           * Panel containing a JLabel and a JTable
           */
          public class LabelTablePanel extends JPanel {

              JTable table;
              JLabel label;

              public LabelTablePanel() {

                  super();

                  label = new JLabel("Label:");
                  label.setDisplayedMnemonic('l');

                  table = new JTable(2, 2);
                  table.addFocusListener(new TableFocusListener());
                  table.setPreferredSize(new Dimension(50, 50));
                  label.setLabelFor(table);

                  add(label);
                  add(table);

              } // constructor

              private class TableFocusListener implements FocusListener {

                  public void focusGained(FocusEvent fe) {

                      System.out.println("TABLE GAINED FOCUS");

                  }

                  public void focusLost(FocusEvent fe) {

                      System.out.println("TABLE LOST FOCUS");

                  }

              } // TableFocusListener

          } // LabelTablePanel

      } // LabelTableest

            hgajewsksunw Hania Gajewska (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: