BorderLayout
GridLayout
GridBagLayout
import java.applet.*;
import java.awt.*;
public class AFlowLayout extends Applet {
public void init () {
setLayout(new FlowLayout());
for(int i = 0; i < 7; i++)
add(new Button("Button " + i));
}
}
|
![]() |
import java.applet.*;
import java.awt.*;
public class ABorderLayout extends Applet {
public void init () {
setLayout(new BorderLayout());
add(BorderLayout.NORTH, new Button("North"));
add(BorderLayout.SOUTH, new Button("South"));
add(BorderLayout.EAST, new Button("East"));
add(BorderLayout.WEST, new Button("West"));
add(BorderLayout.CENTER,new Button("Center"));
}
}
|
![]() |
import java.applet.*;
import java.awt.*;
public class AGridLayout extends Applet {
public void init() {
setLayout(new GridLayout(7,3));
for(int i = 0; i < 7; i++)
add(new Button("Button " + i));
}
}
|
![]() |
import java.awt.*;
import java.applet.*;
public class AGridBagLayout extends Applet {
public void init() {
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(1,1,1,1); // n,w,s,e
c.weightx = c.weighty = 1.0;
c.gridx = 0; c.gridy = 0;
c.gridwidth = 4; c.gridheight=3;
add(new Button("(0|0) 4x3"), c);
c.weightx = c.weighty = 0.0;
c.gridx = 4; c.gridy = 0;
c.gridwidth = 1; c.gridheight=1;
add(new Button("(4|0) 1x1"), c);
c.gridx = 4; c.gridy = 1;
c.gridwidth = 1; c.gridheight=3;
add(new Button("(4|1) 1x3"), c);
c.gridx = 0; c.gridy = 3;
c.gridwidth = 1; c.gridheight=1;
add(new Button("(0|3) 1x1"), c);
c.gridx = 1; c.gridy = 4;
c.gridwidth = 3; c.gridheight=1;
add(new Button("(1|4) 3x1"), c);
}
}
|
![]() |
![[Image]](Layout-Dateien/pict1.jpg)
![[Image]](Layout-Dateien/pict2.jpg)
![[Image]](Layout-Dateien/pict3.jpg)
![[Image]](Layout-Dateien/pict4.jpg)