JDK-6201182 : Button loses focus momentarily and regains when clicking a non focusable list, win32
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-11-29
  • Updated: 2011-01-19
  • Resolved: 2009-06-18
Related Reports
Relates :  
Description
I have a frame with a button and a list. List is non-focusable. Initially button has the focus. But when clicking an item in the list, FOCUS_LOST is triggered for button with opposite component as List and the button regains the focus almost immediately, hence a FOCUS_GAINED event is triggered thereafter. I am actually trying to transfer the focus to the next component inside the action performed. So when double clicking the list, an action event is triggered but kfm.getFocusOwner() returns NULL though button always retains the focus. This is incorrect. Button should not trigger a focus lost event when clicking a non-focusable frame.

This is reproducible only on Win32 and not reproducible on Motif and XToolkit. This is reproducible right from 1.4.

Run the attached test on Win32. You will see a button and a list. Click an item in the list. Check the console. You will get a FOCUS_LOST and a FOCUS_GAINED event. Double click on any of the items in the list. You will see 'Focus Owner: null' message in the console.



Comments
EVALUATION The fix for 6806217 makes focus synthetic on MS Windows (like on XAWT). Native platform no longer receives native focus messages until Java allows it. So, non-focusable component may no loner steal focus.
18-06-2009

EVALUATION The problem is that when clicking a component (no matter is it focusable or not in Java) Windows generates WM_KILLFOCUS on the opposite component. We react by posting FOCUS_LOST to Java. DKFM, dispatching FOCUS_LOST, just sets the global focus owner to NULL and then target the event. When Windows generates WM_SETFOCUS on non-focusable component we post FOCUS_GAINED. And only then DFFM detects that this component is non-focusable and initiates focus restoration process. Non-focusable component receives FOCUS_LOST and some other component receives FOCUS_GAINED. I suspect that only focus hook may solve the problem. ###@###.### 2004-12-23 08:29:49 GMT
23-12-2004