-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.5, 1.1.8_003, 1.3.0
-
generic, x86
-
generic, windows_nt
Name: ccC48265 Date: 11/27/97
=20
This bug is from Oracle, a licensee.
-
If you add a native component (like Button) to a lightweight container
and then call setVisible(false) on the container --prior to the creation
of any peers-- then the native component won't actually get hidden.
The container ends up hidden correctly but the native will show anyway.
-
This create-then-immediately-hide sequence sounds odd, but it's exactly
what happens automatically when you add multiple pages to a CardLayout.
-
It appears that in most cases this bug isn't seen because a LayoutManager
often makes a native vanish in other ways such as setting its size to zero.
This only bit me when putting a native inside a FlowLayout inside a
CardLayout. The code below simplifies this with explicit positioning.
-
POSSIBLE FIX: the helper class Component.NativeInLightFixer could initially
check if the native component has any lightweight ancestor that is hidden,
and if so, hide the native peer. (See 'kick start' in Component.java.)
-
public class AgitatedNative
{
public static void main( String[] args )
{
java.awt.Frame frame =3D new java.awt.Frame( "Please fix me!" );
frame.setSize( 300, 450 );
//
java.awt.Container visible =3D new LightweightContainer();
visible.add( createButton( "I'm visible" ));
//
java.awt.Container hidden =3D new LightweightContainer();
hidden.add( createButton( "I'm hidden" ));
//
visible.setBounds( 50, 50, 200, 150 );
hidden.setBounds( 50, 250, 200, 150 );
frame.setLayout( null );
frame.add( visible );
frame.add( hidden );
//
// if you call this BEFORE peer creation, the lightweight container
// (red box) will be hidden but the native button remains visible..=
.
hidden.setVisible( false );
//
// (this line causes all the peers to get created)
frame.setVisible( true );
//
// ...but if you call this AFTER peer creation, it works correctly
//hidden.setVisible( false );
}
//
static java.awt.Component createButton( String label )
{
java.awt.Component b =3D new java.awt.Button( label );
b.setBounds( 50, 50, 100, 50 );
return b;
}
static class LightweightContainer extends java.awt.Container
{
public void paint( java.awt.Graphics g )
{
g.setColor( java.awt.Color.red ); // x-ray dye
g.fillRect( 0, 0, 999, 999 );
}
}
}
(Review ID: 20762)
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
###@###.### (97-11-27):
I was able to reproduce the bug on both sol2.6 and win32, using=041.1.5;
I could also reproduce the bug with 1.2beta2V.
It seems to me that this bug is strongly related to, if not essentially
a duplicate of, bug 4041321.
======================================================================
- duplicates
-
JDK-4140484 heaveyweight components inside invisible lightweight containers still show
-
- Closed
-