Name: sg39081 Date: 02/20/98
/*
* Here's the problem: Basically, Lightweight Containers have a lot of
* trouble dealing with Heavyweights. Now, we already know about the
* fact that Z-buffering doesn't work because Heavyweights are always
* painted on top of Lightweights. But the problem we've run across here
* is that a Heavyweight which is larger than its Lightweight Container
* is not properly cropped.
*
* In this demonstration we use the HotJavaBrowserBean because our
* program uses that Bean - we are attempting to maximize the Bean, and
* place it in a JScrollPane, thus allowing us to control the appearance
* of the scrollbars. (To be honest, we are using our own Lightweight
* ScrollPane, but JScrollPane shows the same behavior.) If you wanted
* to, you could also demonstrate the problem using Panel rather than
* the browser bean.
*
* There are two ways to fix this problem: the browser bean could be
* composed of a lightweight Panel and a lightweight ScrollPane (say
* JPanel and JScrollPane - or any other lightweight version), rather
* than the Panel and ScrollPane it currently uses, thus making it a
* Lightweight; or Lightweight Containers could somehow be made to
* properly clip their Heavyweight components. This second option
* seems much less likely to even be possible. The first option seems
* like a fairly easy fix. Also, it would allow us to double-buffer
* the HTML component quite easily.
*
* David Levine, ###@###.###
* Dario Laverde, ###@###.###
*
*/
public class LightHeavy
{
public final static int LIGHTWEIGHTDEMO = 0;
public final static int HEAVYWEIGHTDEMO = 1;
// Change this from LIGHTWEIGHTDEMO to HEAVYWEIGHTDEMO to see both cases.
public static int aType = LIGHTWEIGHTDEMO;
public static void main( String[] args)
{
switch( aType)
{
case HEAVYWEIGHTDEMO:
{
//This uses all heavyweights, and works
Frame aFrame = new Frame( "LightHeavy");
aFrame.setLayout( null);
aFrame.setBounds( 100, 100, 300, 300);
aFrame.setBackground( Color.black);
ScrollPane aPane = new ScrollPane( );
HotJavaBrowserBean aBrowser = new HotJavaBrowserBean( );
aBrowser.setBounds( 0, 0, 180, 2500);
aPane.add( aBrowser);
aPane.setBounds( 40, 40, 200, 200);
aFrame.add( aPane);
aFrame.show( );
try
{
aBrowser.setDocumentURL( new URL("http://java.sun.com/"));
}
catch( Exception e)
{
}
break;
}
case LIGHTWEIGHTDEMO:
{
// This adds a heavyweight to a lightweight scrollpane, and is not cropped correctly
Frame aFrame = new Frame( "LightHeavy");
aFrame.setLayout( null);
aFrame.setBounds( 100, 100, 300, 300);
aFrame.setBackground( Color.black);
JScrollPane aPane = new JScrollPane( );
HotJavaBrowserBean aBrowser = new HotJavaBrowserBean( );
aBrowser.setBounds( 0, 0, 180, 2500);
aPane.setViewportView( aBrowser);
aPane.setBounds( 40, 40, 200, 200);
aFrame.add( aPane);
aFrame.show( );
try
{
aBrowser.setDocumentURL( new URL("http://java.sun.com/"));
}
catch( Exception e)
{
}
break;
}
default:
break;
}
}
}
(Review ID: 22695)
======================================================================