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

Lightweight Comp.: calling requestfocus inside of a focus_gained handler fail

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1
    • Resolution: Fixed
    • Affects Version/s: 1.1.4
    • Fix Version/s: 1.1.5
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.1.5
    • CPU:
      x86
    • OS:
      windows_95
    • Verification:
      Verified

      Description


      ingrid.yao@Eng 1997-08-08

      Oracle showstopper bug#523611:
      ==================================
      If, in a FOCUS_GAINED handler for a lightweight component, you try
      to call requestFocus() to shift the focus to another view, the
      request fails.
      The problem is, I believe, in LightweightDispatcher.setFocusRequest,
      in the code:
           
      if (focusOwner == nativeContainer) {
        // This container already has focus so just
        // send FOCUS_GAINED event to lightweight component
        c.dispatchEvent(new FocusEvent(c, FocusEvent.FOCUS_GAINED ... )
        peerNeedsRequest = false;
      }
      The problem is that "focus" isn't yet set to "c" - that
      doesn't happen until the end of the function. But this means
      that, when focusRequest() is called inside of the FOCUS_GAINED
      handler, the LightweightDispatcher might think the requestFocus()
      is being invoked on the component that already has the focus,
      in which case it ignores the request.
       
      TESTCASE
      ===============
                             
      Code to repro the problem follows. The code tries to keep
      focus on #2. Note that if FocusComp is changed to extend
      Canvas instead of Component, the given code works fine.
          
      import java.awt.*;
      import java.awt.event.*;
      public class FocusBug extends Frame implements FocusListener
      {
        public static void main(String[] args)
        {
          new FocusBug();
        }
        public FocusBug()
        {
          super();
          setLayout(new FlowLayout());
          _c1 = new FocusComp("#1");
          _c1.addFocusListener(this);
          _c2 = new FocusComp("#2");
          add(_c1);
          add(_c2);
          pack();
          setVisible(true);
        }
        public void focusGained(FocusEvent e)
        {
          _c2.requestFocus();
        }
        public void focusLost(FocusEvent e) {}
        private Component _c1;
        private Component _c2;
      }
      class FocusComp extends Component implements FocusListener
      {
        public FocusComp(String name)
        {
          super();
          addFocusListener(this);
          setName(name);
          setSize(10, 10);
        }
        public boolean isFocusTraversable()
        {
          return true;
        }
        public void focusGained(FocusEvent e)
        {
          System.out.println(e);
        }
        public void focusLost(FocusEvent e)
        {
          System.out.println(e);
        }
      }
       

        Attachments

          Activity

            People

            Assignee:
            duke J. Duke (Inactive)
            Reporter:
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: