JDK-6332772 : update Component#remove() javadoc to reflect need to call revalidate()
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-10-05
  • Updated: 2017-05-16
  • Resolved: 2006-03-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b75Fixed
Related Reports
Relates :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
According to this bug:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4130347
, and my own experience,  calling java.awt.Component#remove(*) to remove a component requires a call to revalidate() or validate().

It's not a bug report per se, rather a RFE that the requirements
of the remove() calls be explicitly noted in the javadoc so that
people don't get bitten by this.

I only very occasionally produce code that ever does a
Component#remove()
Component#add()
sequence.

But every time I have, it has been a frustrating experience.
First the code seem to work. Then it doesn't work under odd
situations. Then it does an incompletel repaint.
Eventually..... I either remember or find some comment somewhere about
needing to do a
validate()
repaint()
sequence, and then everything works fine.

If the remove() methods just had a comment along the lines of:
"Client code should call revalidate() and repaint() after completing
modications to the list of child components".
Then that would be one less swing quirk that I have to keep running into.


JUSTIFICATION :
I have been bitten by this a couple of times because it can sometimes work and then mysteriously not work.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It would be useful if the remove()/add() javadoc explicitly stated the requirement.

Comments
SUGGESTED FIX http://ccc.sfbay/6332772
28-12-2005

EVALUATION Add method already contains such note: * Note: If a component has been added to a container that * has been displayed, <code>validate</code> must be * called on that container to display the new component. * If multiple components are being added, you can improve * efficiency by calling <code>validate</code> only once, * after all the components have been added. Adding a component usually needs also repaint() call because comps might intersect each other.
26-10-2005

EVALUATION spec change
26-10-2005

SUGGESTED FIX *** /tmp/geta12798 26 12:15:34 2005 --- Container.java 26 12:15:32 2005 *************** *** 1093,1098 **** --- 1093,1100 ---- * This method also notifies the layout manager to remove the * component from this container's layout via the * <code>removeLayoutComponent</code> method. + * Should call repaint() after completing + * modifications to reflect the changes on screen. * * @param index the index of the component to be removed * @see #add
26-10-2005