Informatik/Java/Grafische Oberfläche/GUI/Layout FlowLayout
BorderLayout
GridLayout
GridBagLayout

FlowLayout

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));
  }
}
				
		


[Image]

BorderLayout

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"));
  }
}
      
	  


[Image]

GridLayout

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));
  }
		
}
      
		


[Image]

GridBagLayout

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]