[3629] in java-interest

home help back first fref pref prev next nref lref last post

Problems with Panel::paint()

daemon@ATHENA.MIT.EDU (sc@cen.com)
Mon Nov 20 18:27:44 1995

From: sc@cen.com
Date: Mon, 20 Nov 1995 14:08:30 -0500
To: java-interest@java.sun.com

I'm having trouble getting hierarchies of nested panels to paint
themselves properly.  It appears that the default paint() method for
Applet never invokes the paint methods for Components nested within
it.  For example, consider the following code:

    import java.applet.Applet;
    import java.awt.*;

    public class Foo extends Applet {

        public synchronized void init() {
            MyPanel p = new MyPanel();
            p.setLayout(null);
            Button b = new Button("Button");
            p.add(b);
            setLayout(null);
            add(p);
        }

        public void paint(Graphics g) {
            System.out.println("Foo paint()");
            g.setColor(Color.red);
            g.drawRect(0, 0, 30, 30);
            super.paint(g);
        }
    }

    class MyPanel extends Panel {
        public MyPanel() { }

        public void paint(Graphics g) {
            System.out.println("MyPanel paint()");
            super.paint(g);
        }
    }

This applet never prints "MyPanel paint()", although it does print
"Foo paint()" at the expected junctures.

Is this behavior intentional?  And if so, why??

BTW, I'm on Solaris, and both the appletviewer and Netscape 2.0 beta 2
exhibit this behavior.

thanks,
-steve
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post