43 |
import java.awt.event.ContainerListener; |
import java.awt.event.ContainerListener; |
44 |
import java.awt.event.KeyEvent; |
import java.awt.event.KeyEvent; |
45 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
46 |
|
import java.awt.peer.ComponentPeer; |
47 |
import java.awt.peer.ContainerPeer; |
import java.awt.peer.ContainerPeer; |
48 |
import java.awt.peer.LightweightPeer; |
import java.awt.peer.LightweightPeer; |
49 |
import java.beans.PropertyChangeListener; |
import java.beans.PropertyChangeListener; |
343 |
comp.parent.remove(comp); |
comp.parent.remove(comp); |
344 |
comp.parent = this; |
comp.parent = this; |
345 |
|
|
|
// Notify the component that it has a new parent. |
|
|
comp.addNotify(); |
|
|
|
|
346 |
if (peer != null) |
if (peer != null) |
347 |
{ |
{ |
348 |
|
// Notify the component that it has a new parent. |
349 |
|
comp.addNotify(); |
350 |
|
|
351 |
if (comp.isLightweight ()) |
if (comp.isLightweight ()) |
352 |
{ |
{ |
353 |
enableEvents (comp.eventMask); |
enableEvents (comp.eventMask); |
760 |
{ |
{ |
761 |
if (!isShowing()) |
if (!isShowing()) |
762 |
return; |
return; |
763 |
// Paint self first. |
|
|
super.paint(g); |
|
764 |
// Visit heavyweights as well, in case they were |
// Visit heavyweights as well, in case they were |
765 |
// erased when we cleared the background for this container. |
// erased when we cleared the background for this container. |
766 |
visitChildren(g, GfxPaintVisitor.INSTANCE, false); |
visitChildren(g, GfxPaintVisitor.INSTANCE, false); |
778 |
* @specnote The specification suggests that this method forwards the |
* @specnote The specification suggests that this method forwards the |
779 |
* update() call to all its lightweight children. Tests show |
* update() call to all its lightweight children. Tests show |
780 |
* that this is not done either in the JDK. The exact behaviour |
* that this is not done either in the JDK. The exact behaviour |
781 |
* seems to be that top-level container call super.update() |
* seems to be that the background is cleared in heavyweight |
782 |
* (causing the background to be cleared), and all other containers |
* Containers, and all other containers |
783 |
* directly call paint(), causing the (lightweight) children to |
* directly call paint(), causing the (lightweight) children to |
784 |
* be painted. |
* be painted. |
785 |
*/ |
*/ |
786 |
public void update(Graphics g) |
public void update(Graphics g) |
787 |
{ |
{ |
788 |
if (getParent() == null) |
// It seems that the JDK clears the background of containers like Panel |
789 |
super.update(g); |
// and Window (within this method) but not of 'plain' Containers or |
790 |
|
// JComponents. This could |
791 |
|
// lead to the assumption that it only clears heavyweight containers. |
792 |
|
// However that is not quite true. In a test with a custom Container |
793 |
|
// that overrides isLightweight() to return false, the background is |
794 |
|
// also not cleared. So we do a check on !(peer instanceof LightweightPeer) |
795 |
|
// instead. |
796 |
|
ComponentPeer p = peer; |
797 |
|
if (p != null && !(p instanceof LightweightPeer)) |
798 |
|
g.clearRect(0, 0, getWidth(), getHeight()); |
799 |
|
|
800 |
paint(g); |
paint(g); |
801 |
} |
} |
802 |
|
|