
//Titel:        GridBagLayout


// GridbagLayout10.java	Editoreingabe mit GridbagLayout
// Editor mit horizontal Ausrichtung
// Alternative Syntax

import java.awt.*;
import javax.swing.*;

import java.awt.event.*;


public class GridBagLayout03aa extends JFrame {

  JLabel jLabel1 = new JLabel();
  JTextField TEdit1 = new JTextField("TEdit1 (60%)");
  JTextField TEdit2 = new JTextField("TEdit2 (40%)");
  JTextField TEdit3 = new JTextField("TEdit3 (30%)");
  JTextField TEdit4 = new JTextField("TEdit4 (70%)");
  JTextField TEdit5 = new JTextField("TEdit5 (30%)");
  JLabel jLabel2 = new JLabel();

  JButton BnOk = new JButton();
  JButton BnESC = new JButton();

  public GridBagLayout03aa() {
    setSize(500, 340);
    setTitle("GridBagLayout03a. Beispiel");
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
  }

  private void setGUI() {
    this.getContentPane().setLayout( new GridBagLayout() );

    jLabel1.setText("1. Label");
    jLabel2.setText("2. Label");

    jLabel1.setFont( new Font("Arial", Font.BOLD,18)  );
    jLabel2.setFont( new Font("Arial", Font.BOLD,18)  );

    TEdit1.setFont( new Font("Arial", Font.BOLD,18)  );
    TEdit2.setFont( new Font("Arial", Font.BOLD,18)  );
    TEdit3.setFont( new Font("Arial", Font.BOLD,18)  );
    TEdit4.setFont( new Font("Arial", Font.BOLD,18)  );
    TEdit5.setFont( new Font("Arial", Font.BOLD,18)  );

    BnOk.setText("Ok");
    BnESC.setText("Abbruch");
    BnOk.setFont( new Font("Arial", Font.BOLD,18)  );
    BnESC.setFont( new Font("Arial", Font.BOLD,18)  );


    int w=BnESC.getWidth();
    int h=BnESC.getHeight();
    BnOk.setPreferredSize( BnESC.getPreferredSize() );

  JPanel paneloben = new JPanel();
    paneloben.setLayout( new GridBagLayout() );
   paneloben.setBackground(Color.RED);

  this.getContentPane().add(paneloben,
        new GridBagConstraints(0, 0, 4, 1, 100.0, 0.0
            ,GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0,0,0,0), 0, 0));

    paneloben.add(jLabel1,
       new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(10,10,40,0), 0, 0));

  
  
    paneloben.add(TEdit1, 
            new GridBagConstraints(1, 0, 1, 1, 100.0, 0.0
            ,GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(10,10,40,10), 0, 0));
             

    paneloben.add(TEdit2,
        new GridBagConstraints(2, 0, 1, 1, 28.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
            new Insets(10,10,40,10), 0, 0));

   paneloben.add(TEdit3,
        new GridBagConstraints(3, 0, 1, 1, 30.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
            new Insets(10,10,40,10), 0, 0));



    this.getContentPane().add(jLabel2,
         new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE,
            new Insets(0,10,40,0), 0, 0));

    this.getContentPane().add(TEdit4,
        new GridBagConstraints(1, 1, 2, 1, 70.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
            new Insets(0,10,40,10), 0, 0));

    this.getContentPane().add(TEdit5,
        new GridBagConstraints(3, 1, 1, 1, 30.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
            new Insets(0,10,40,10), 0, 0));


    JTextArea TEdit6 = new JTextArea("Hallo\n2.Zeile");
  this.getContentPane().add(TEdit6,
        new GridBagConstraints(0, 2, 4, 1, 100.0, 100.0
            ,GridBagConstraints.WEST, GridBagConstraints.BOTH,
            new Insets(0,10,40,10), 0, 0));


    JPanel pn = new JPanel();
    pn.add(BnOk);
    pn.add(BnESC);
    pn.setBackground(Color.green);
    this.getContentPane().add(pn,
           new GridBagConstraints(0, 3, 4, 1, 1.0, 0.0
            ,GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0,0,0,0), 0, 0));
  }  // setGUI


  public static void main(String[] args) {
    GridBagLayout03aa frame = new GridBagLayout03aa();
    frame.setVisible(true);
 }

}

