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

setNextFocusableComponent no longer backward compatible

    XMLWordPrintable

Details

    Description

      Name: gm110360 Date: 09/17/2001


      java version "1.4.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
      Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)


      setNextFocusableComponent in JComponent is not backward compatible. In the 1.4
      all JComponents within a setNextFocusableComponent chain must reside within the
      same JFrame, more precisely all components need to have the same
      getFocusCycleRootAncestor (). This makes it impossible to have (disabled)
      JComponents which are part of a focus chain but have not (yet) been added to the
      JFrame (they will have null as FocusCycleRootAncestor). results is a
      IllegalArgumentException: "focusCycleRoot is not a focus cycle root of
      aComponent" being thrown when you call focusNextComponent. I also got null
      pointer Exceptions on the destroy of the applet, but this only happens on
      Solaris/NS4 not under Windows/(NS6/IE6). Probably because a
      FocusCycleRootAncestor is null :

      java.lang.NullPointerException
      at javax.swing.JComponent.deregisterNextFocusableComponent(JComponent.java:986)
      at javax.swing.JComponent.removeNotify(JComponent.java:4302)
      at javax.swing.JTable.removeNotify(JTable.java:480)
      at java.awt.Container.removeNotify(Container.java:1881)
      at javax.swing.JComponent.removeNotify(JComponent.java:4295)
      at java.awt.Container.removeNotify(Container.java:1881)
      at javax.swing.JComponent.removeNotify(JComponent.java:4295)
      at java.awt.Container.removeNotify(Container.java:1881)
      at javax.swing.JComponent.removeNotify(JComponent.java:4295)
      at java.awt.Container.removeNotify(Container.java:1881)
      at javax.swing.JComponent.removeNotify(JComponent.java:4295)
      at java.awt.Container.removeNotify(Container.java:1881)
      at javax.swing.JComponent.removeNotify(JComponent.java:4295)
      at java.awt.Container.removeNotify(Container.java:1881)
      at javax.swing.JComponent.removeNotify(JComponent.java:4295)
      at java.awt.Container.removeNotify(Container.java:1881)
      at javax.swing.JComponent.removeNotify(JComponent.java:4295)
      at java.awt.Container.removeNotify(Container.java:1881)
      at javax.swing.JComponent.removeNotify(JComponent.java:4295)
      at java.awt.Container.removeNotify(Container.java:1881)
      at javax.swing.JComponent.removeNotify(JComponent.java:4295)
      at javax.swing.JRootPane.removeNotify(JRootPane.java:679)
      at java.awt.Container.removeNotify(Container.java:1881)
      at java.awt.Container.removeNotify(Container.java:1881)
      at
      sun.plugin.viewer.MNetscapePluginObject.destroyPlugin(MNetscapePluginObject.java:708)
      at sun.plugin.navig.motif.Plugin.doit(Plugin.java:247)
      at sun.plugin.navig.motif.Plugin.start(Plugin.java:105)


      Here is a little demo to show the problem:

      -----

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

      public class Test
      {
          JButton hello, world, advanced;
          JFrame f;
          JPanel p;

          public Test ()
          {
              f = new JFrame ();
              Container contentPane = f.getContentPane();

              p = new JPanel ();
              contentPane.add (p);
              hello = new JButton ("Hello");
              p.add (hello);
              world = new JButton ("World");
              p.add (world);
              advanced = new JButton ("Advanced Button");
              hello.setNextFocusableComponent (world);
              world.setNextFocusableComponent (advanced);
              advanced.setNextFocusableComponent (hello);
              advanced.setEnabled (false);

              ActionListener al = new ActionListener () {
                  public void actionPerformed (ActionEvent e)
                  {
                      if (e.getSource () == hello)
                      {
                          p.add (advanced);
                          advanced.setEnabled (true);
                          p.revalidate ();
                      }
                      else if (e.getSource () == advanced)
                      {
                          p.remove (advanced);
                          advanced.setEnabled (false);
                          p.revalidate ();
                      }

                      FocusManager.getCurrentManager ().focusNextComponent
      ((JComponent) e.getSource ());
                      System.out.println (((JButton) e.getSource ()).getText ());
                  }
              };
              hello.addActionListener (al);
              world.addActionListener (al);
              advanced.addActionListener (al);

              f.setBounds (200, 200, 200, 200);
              f.setVisible (true);
          }

          public static void main (String[] args)
          {
              Test t;

              t = new Test ();
          }
      }

      ------

      Clicking on "World" before "Hello" will throw a exception
      (Review ID: 132041)
      ======================================================================

      Attachments

        Activity

          People

            alexp Alexander Potochkin (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: