[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [cp-patches] RFC: java.awt.DefaultKeyboardFocusManager fix
From: |
Thomas Fitzsimmons |
Subject: |
RE: [cp-patches] RFC: java.awt.DefaultKeyboardFocusManager fix |
Date: |
Thu, 30 Jun 2005 20:08:45 -0400 |
On Wed, 2005-06-29 at 22:01 +0200, Jeroen Frijters wrote:
> Thomas Fitzsimmons wrote:
> > On Wed, 2005-06-29 at 15:14 +0200, Jeroen Frijters wrote:
> > > Hi,
> > >
> > > Can someone who is more up to speed with AWT please take a
> > > look at the attached patch? While running some AWT code I got
> > > a ClassCastException in this code and while I didn't quite
> > > understand the point of the code (or why it failed), it looked
> > > to me as if the logic was wrong. It tries to find the toplevel
> > > window, but if it doesn't find it, it still goes
> > > ahead and casts the component to a window.
> >
> > What is the component that is being cast to a window that causes the
> > ClassCastException? This code assumes that target is either
> > a window or
> > packed in a window. If that assumption holds, then the only time that
> > parent == null is when target is a window with a null parent. In this
> > case, the while loop will fall through and toplevel will be assigned
> > target.
> >
> > Maybe a focus event is being delivered to a component that isn't yet
> > packed in a window, or that has just been removed from a
> > window? In any case, I'd be interested to know what components are
> > involved.
>
> My guess is that the focus event is delivered to a component that is
> removed from a window. This could very well be due to a bug in my AWT
> peers, but I still believe the current code is obviously wrong, I just
> don't know what the best fix is.
OK. My problem with your patch is that it only sets the focus owner
when parent != null. But parent can be null when target is a window.
In that case, that window's focus owner wouldn't be set.
How about this instead:
// If the parent is null and target is not a window, then target is an
unanchored
// component and so we don't want to set the focus owner.
if (! (parent == null && ! (target instanceof Window)))
{
Window toplevel = parent == null ?
(Window) target : (Window) parent;
...
}
Maybe we should add a comment about target potentially being a window.
Tom
>
> Unfortunately I only saw this problem in a large non-free application
> and I don't really have a clue on how to reproduce this.
>
> Regards,
> Jeroen