GridBagLayout question

From: Daniel Tahin (daniel_tahin_at_web.de)
Date: 03/27/05


Date: Sun, 27 Mar 2005 21:38:21 +0200

Hi newsgroup folks,

can everybody alter the applet code below that the buttons and labels
will not appear in the middle but at the beginning? Can`t do the task
with GridBagLayout...
Thanks in advance, Daniel

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

public class TestApplet extends Applet
{
    public void stop()
    {
       System.out.println("stop called");
    }

    public void init ()
    {

 ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
        sp.setSize(200,200);
 GridBagLayout g = new GridBagLayout();

 GridBagConstraints c = new GridBagConstraints();
 c.weightx=1.0;
 c.weighty=0.0;

 Panel p = new Panel(g);

 for (int i=0; i<3; i++)
 {

     c.gridy++;

            Button button1 = new Button("test");
            g.setConstraints(button1,c);
            p.add (button1);

            Label l = new Label("test");
     g.setConstraints(l,c);
     p.add (l);

            Button button2 = new Button("test");
            g.setConstraints(button2,c);
            p.add (button2);
 }

 sp.add(p);
 add(sp);

    }

}

The .html file:

<html>
<body>
<applet code = "TestApplet.class" width=400 height=400></applet>
</body>
</html>


Quantcast