JDK-4114023 : HotJava bean fails to integrate properly with lightweight containers (e.g. w/JFC
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1998-02-20
  • Updated: 2007-06-18
  • Resolved: 2007-06-18
Related Reports
Duplicate :  
Description

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)
======================================================================

Comments
EVALUATION The problem seems to become fixed with fixing the CR 4811096 (Allow mixing of heavy and lightweight components).
18-06-2007

EVALUATION This is the classic z-order AWT/lightweight component problem. It would be extremely difficult to fix this at the AWT level (where ideally it should be fixed). Hotjava really should migrate to using lightweight containers. amy.fowler@Eng 2000-03-15 The problem isn't that light weights aren't clipping the heavy weights, the problem is that heavy weights often times don't honor the clip rect, or draw directly in their Graphics, circumventing the Swing painting subsystem. In order to fix this we would likely need to promote getVisualRect that is in JComponent and tell heavy weight components to honor this. As this is a change that would have to be in awt, I'm reassigning to them for further consideration. ###@###.### 2001-10-22
22-10-2001