[2939] in java-interest

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

Components and containers

daemon@ATHENA.MIT.EDU (Ed Anuff)
Sat Oct 21 06:25:08 1995

Date: Wed, 18 Oct 1995 21:06:25 -0800
To: java-interest@java.sun.com
From: edanuff@protagonist.com (Ed Anuff)
Cc: java@java.sun.com

Like others on this list, I'm having a tough time with getting components
to lay out and resize correctly.  I've included the source for an example
applet that I'm using to test this out.  I would expect that the panel is
layed out at 100,100 and that the canvas would be positioned at 100,100
within the panel.

----------------------
|Applet              |
|                    |
|                    |
|      --------------|
|      |Panel1       |
|      |             |
|      |             |
|      |       ------|
|      |       |\ | /|
|      |       | \|/ |
|      |       |--\--|
|      |       | /|\ |
|      |       |/ | \|
----------------------

When run, everything displays at 0,0 (in the applet viewer - in Netscape
nothing displays).  My question is whether this is supposed to be the way
this works or if its a bug?  If its a bug, is it planned to be fixed in the
next rev?  BTW, I'm aware of the reasons why absolute placement is not a
good idea, but nothing in this example is platform dependent.

Ed


-Hierarchy.java start---------------------------
import java.util.*;
import java.applet.*;
import java.awt.*;

public class Hierarchy extends Applet {

        Panel panel1;
        TestCanvas theCanvas;

        public void init() {
                resize(400, 400);
                setLayout(null);

                panel1 = new Panel();
                panel1.setLayout(null);
                panel1.reshape(100,100,200,200);
                add(panel1);

                theCanvas = new TestCanvas();
                theCanvas.reshape(100,100,100,100);
                panel1.add(theCanvas);

                panel1.move(100,100);
                theCanvas.move(100,100);

                repaint();

                System.out.println(location().x + ", " + location().y + ",
" + size().width + ", " + size().height);
                System.out.println(panel1.location().x + ", " +
panel1.location().y + ", " + panel1.size().width + ", " +
panel1.size().height);
                System.out.println(theCanvas.location().x + ", " +
theCanvas.location().y + ", " + theCanvas.size().width + ", " +
theCanvas.size().height);


        }

        public void start() {
                repaint();

                System.out.println(location().x + ", " + location().y + ",
" + size().width + ", " + size().height);
                System.out.println(panel1.location().x + ", " +
panel1.location().y + ", " + panel1.size().width + ", " +
panel1.size().height);
                System.out.println(theCanvas.location().x + ", " +
theCanvas.location().y + ", " + theCanvas.size().width + ", " +
theCanvas.size().height);

        }

}

class TestCanvas extends Canvas {
    public TestCanvas() {
    }

    public void paint(Graphics g) {
                Rectangle r = bounds();

                g.drawRect(0, 0, r.width-1, r.height-1);
                g.drawLine(0, 0, r.width, r.height);
                g.drawLine(r.width, 0, 0, r.height);
                g.drawLine(0, r.height / 2, r.width, r.height / 2);
                g.drawLine(r.width / 2, 0, r.width / 2, r.height);
    }
}
-Hierarchy.java end-----------------------------



Ed Anuff
Protagonist Interactive
edanuff@protagonist.com
http://www.protagonist.com/


-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

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