Franz |
GridBagLayout
Meine Frage:
Hallo bin grad an folgendem Programm:
import java.awt.*;
import java.awt.Event.*;
import javax.swing.*;
public class Adresseingabe extends JFrame
{
Container ContentPane=getContentPane();
Adresseingabe()
{
JLabel L1= new JLabel("Bitte geben Sie ihre Daten ein:");
JLabel L2= new JLabel("Name:");
JLabel L3= new JLabel("Telefon:");
JLabel L4= new JLabel("Fax:");
JLabel L5= new JLabel("Email:");
JTextField TF1= new JTextField(10);
JTextField TF2= new JTextField(10);
JTextField TF3= new JTextField(10);
JTextField TF4= new JTextField(10);
JButton B1= new JButton("OK");
JButton B2= new JButton("Abbrechen");
JPanel P1= new JPanel();
JPanel P2= new JPanel();
JPanel P3= new JPanel();
JPanel P4= new JPanel();
JPanel P5= new JPanel();
GridBagLayout gbl= new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
P1.setLayout(new FlowLayout(0));
P2.setLayout(new GridBagLayout());
P3.setLayout(new FlowLayout(2));
P1.add(L1);
gbc.gridx=0;
gbc.gridy=0;
gbc.gridwidth=2;
gbc.gridheight=1;
gbl.setConstraints(L2, gbc);
P2.add(L2);
gbc.gridx= 0;
gbc.gridy=1;
gbc.gridwidth=2;
gbc.gridheight=1;
gbl.setConstraints(L3, gbc);
P2.add(L3);
gbc.gridx=2;
gbc.gridy=0;
gbc.gridwidth=3;
gbc.gridheight=1;
gbl.setConstraints(TF1, gbc);
P2.add(TF1);
gbc.gridx=0;
gbc.gridy=2;
gbc.gridwidth=2;
gbc.gridheight=1;
gbl.setConstraints(L4, gbc);
P2.add(L4);
gbc.gridx=2;
gbc.gridy=1;
gbc.gridwidth=3;
gbc.gridheight=1;
gbl.setConstraints(TF2, gbc);
P2.add(TF2);
gbc.gridx=0;
gbc.gridy=3;
gbc.gridwidth=2;
gbc.gridheight=1;
gbl.setConstraints(L5, gbc);
P2.add(L5);
gbc.gridx=2;
gbc.gridy=2;
gbc.gridwidth=3;
gbc.gridheight=1;
gbl.setConstraints(TF3, gbc);
P2.add(TF3);
gbc.gridx=2;
gbc.gridy=3;
gbc.gridwidth=3;
gbc.gridheight=1;
gbl.setConstraints(TF4, gbc);
P2.add(TF4);
P3.add(B1);
P3.add(B2);
ContentPane.add(P1,BorderLayout.NORTH);
ContentPane.add(P2,BorderLayout.CENTER);
ContentPane.add(P3,BorderLayout.SOUTH);
ContentPane.add(P4,BorderLayout.EAST);
ContentPane.add(P5,BorderLayout.WEST);
setLocation(200,200);
setSize(300,300);
setTitle("AdressEingabe");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[]args)
{
new Adresseingabe();
}
}
Meine Ideen:
So, also das Problem liegt beim GridBagLayout es soll folgendermaßen aussehn:
Name: Textfeld
Telefon: Textfeld
Fax: Textfeld
Email : Textfeld
Es wird aber immer nebeneinander angeordnet.
Wo liegt denn hierbei noch mein Fehler? |