JDK-4959482 : ContainerOrderFocusTraversalPolicy not working as expected
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.2,5.0,6
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2003-11-25
  • Updated: 2013-08-20
  • Resolved: 2009-06-15
Related Reports
Relates :  
Relates :  
Description
If I make a component as focusTraversalPolicyProvider(RFE 4719336) and set its focus policy to ContainerOrderFocusTraversalPolicy than it
is not moving focus in the child components using traversal key as expected.

Attached are two tests AWTFocusTest.java & SwingFocusTest.java

Steps to reproduce:
a) Run either of test case AWTFocusTest/SwingFocusTest
b) Click on button "Start test"
c) This should move the focus to each textfield, But none of the 
   textfield gets focus, And so focusGained is never called.

Now go to line(Either of testcase) 19 and uncomment it and comment line 20. 
Now run modified testcase, It will now use LayoutFocusTraversalPolicy, 
Now run the test and it will move focus as expected and display following 
console message
Expected component to get focus: Component 1
   focusGained: Component 1
  Expected component to get focus: Component 2
   focusGained: Component 2
  Expected component to get focus: Component 3
   focusGained: Component 3

Following is the attached mail which have some discussion on this issue.
--------------------------------------------------------------------
Hi Hemant,

I've evaluated the problem you describe and I think this is a bug.
Could you pelase file it (please attache both Swing and AWT tests
to it).

With best regards, Oleg.

On Mon, Nov 24, 2003 at 03:18:26PM +0300, Roman S. Poborchy wrote:

>> Alright, we'll look into that.
>> 
>> Hemant Singh wrote:
>> 
>
>>> > Hi Roman,
>>> > Thanks for the time.
>>> >
>>> > Roman I have converted testcase(AWTFocusTest) to AWT & attached.
>>> > Problem still seems to be there.
>>> > Just like in swing here also LayoutFocusTraversalPolicy works fine but
>>> > ContainerOrderFocusTraversalPolicy not behaving as expected, Can you
>>> > have a look on it.
>>> >
>>> > The way you need to run the test remains the same, As this is same test
>>> > but now using AWT component/container instead of Swing component/container.
>>> >
>>> > Regards
>>> > Hemamt
>>> >
>>> > Attachment: AWTFocusTest.java
>>> >
>>> > Roman S. Poborchy wrote:
>>> >
>>
>>>> > > Hi Hemant,
>>>> > >
>>>> > > Hemant Singh wrote:
>>>> > >
>>>> > >
>>>
>>>>> > >>Sorry for sending you complete test case and indeed it was under development so was bit cluttered
>>>>> > >>also.
>>>>> > >>I have attached(AWTFocusTest) a small testcase specific to problem.
>>>>> > >>- I have tested it on Win2k and Solaris 5.8
>>>>> > >>Description about problem:
>>>>> > >>- Run the attached testcase.
>>>>> > >>- Click on button start test. This will make a thread which moves in current focus traversal
>>>>> > >>policy
>>>>> > >>  till last component and press forward traversal key for each component and expects that
>>>>> > >>component
>>>>> > >>  to receive focus on it.
>>>>> > >>When you will run it you should have output on console something like.
>>>>> > >>Expected component to get focus: Component 1
>>>>> > >> focusGained: Component 1
>>>>> > >>Expected component to get focus: Component 2
>>>>> > >> focusGained: Component 2
>>>>> > >>Expected component to get focus: Component 3
>>>>> > >> focusGained: Component 3
>>>>> > >>This is the output if I use LayoutFocusTraversalPolicy,
>>>>> > >>But now if you modify the test case(Comment line 17 and uncomment line 18) to use
>>>>> > >>ContainerOrderFocusTraversalPolicy
>>>>> > >>than it doesn't work as expected and components don't get focus on traversal key press.
>>>>> > >>Please ping me back If you have any problem in running or confusion about it at any point.
>>>
>>>> > >
>>>> > >
>>>> > > Now I've run this test and I think I know what the problem is.
>>>> > > ContainerOrderFocusTraversalPolicy can't work with Swing components and
>>>> > > Containers. If you write a pure AWT testcase (with Frame, Panels, Textields and
>>>> > > Buttons, for example), it will work with ContainerOrderFocusTraversalPolicy.
>>>> > > Likewise, LayoutFocusTraversalPolicy is going to have troubles with pure
>>>> > > AWT testcase.
>>>> > >
>>>> > > The problem is, it isn't mentioned anywhere in the doc that this policy shouldn't
>>>> > > be used for Swing components. We thought it would be enough to have the
>>>> > > correct policy select by default according to Container's type.
>>>> > >
>>>> > > So, doc clarification might be needed,  but the behaviour is intended.
>>>> > >
>>>> > > Thanks,
>>>> > >
>>>> > > Roman
>>>> > >
>>
>>> >
>>> >   ----------------------------------------------------------------------------------------------------
>>> >                         Name: AWTFocusTest.java
>>> >    AWTFocusTest.java    Type: Plain Text (text/plain)
>>> >                     Encoding: 7BIT

Comments
EVALUATION In the testcase JApplet is used as an FTP provider container. JApplet is a special container that accept focus on itself. So, when 'Start test' button is focused and TAB is pressed focus goes to JApplet. Then focus is stuck on JApplet because itself is the default component to focus in its focus cycle. I see no AWT problems in JDK 7. In order to make the test work either of the following should be made: 1. replace JApplet with JPanel (making it unfocusable by default); 2. make a textfield the default component to focus in JApplet's focus cycle.
15-06-2009

WORK AROUND Add this line to the code: container.setFocusable(false);
28-06-2006

EVALUATION Name: osR10079 Date: 11/28/2003 The cause of the problem is that our traversal policy's code which handles policy providers assumes that provider's policy will not accept provider itself, but this is wrong assumption and it should be removed. ###@###.### Nov 28 2003 ======================================================================
14-08-2004