[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: Component invalidate() fix
From: |
Roman Kennke |
Subject: |
[cp-patches] FYI: Component invalidate() fix |
Date: |
Mon, 07 Nov 2005 22:31:46 +0000 |
Hi,
The invalidate() method in java.awt.Component always needs to go up the
tree to the top, regardless if the valid flag is set or not on some
parent. To explain this I'll best describe the bug that I've seen.
What happened was this: The component tree was invalidated by a call to
invalidate(). A layout manager somewhere at the top of the tree throws
away its state in response to that. Then somehow the getPreferredSize
method gets called, causing the layoutmanager to save its result for the
preferredSize (note: the component has not been layouted so it is still
not valid). After that, another component is added to the tree, causing
another invalidate() call. Since the component above is still invalid,
this call would not bubble up the tree to the top, so the layoutmanager
does not throw away its state for the preferredSize (although this is
clearly wrong at this point). This wrong preferredSize then leads to
wrong size calculations during the actual layout (in my case triggered
by a pack() call). Several solutions came to my mind to fix this:
1. Fix the layoutmanager to check if the container is valid. This
solution is clearly wrong, since I talk about an application layout
manager and not GNU Classpath. This means that layout managers can
expect to have their invalidateLayout() method really called everytime
when layout information must be thrown away.
2. Fix the call to getPreferredSize() et al to call invalidateLayout() on
the LM if the container is not yet marked valid. This also seems
somewhat wrong because this might throw away the cached state more often
than needed.
3. This patch. Elegant and short. :-D
2005-11-07 Roman Kennke <address@hidden>
* java/awt/Component.java
(invalidate): Invalidate up the whole tree, regardless if some
parent is already marked invalid. This is needed in some
situations
for layout managers to throw away their cache.
/Roman
Component.diff
Description: Text Data
- [cp-patches] FYI: Component invalidate() fix,
Roman Kennke <=