
// Beispiel mit GridBagLayout und einem Editor
// weighty  und BOTH

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

import java.awt.event.*;

public class GridBagLayout05 extends JFrame {

  JLabel jLabel1 = new JLabel();
  JTextField TName = new JTextField();

  JLabel jLabel2 = new JLabel();
  JTextArea TEdit = new JTextArea("Hallo\n2.Zeile");

  JButton BnOk = new JButton("Ok");
  JButton BnEsc = new JButton("Abbruch");


  public GridBagLayout05() {
    setSize(400, 350);
    setTitle("GridBagLayout05. Beispiel");
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
  }

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

    jLabel1.setText("Name");
    TName.setText("-");

    jLabel2.setText("Einträge");

    BnEsc.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(ActionEvent e) {
        BnEsc_Clicked();
      }
    });


    this.getContentPane().add(jLabel1,
        new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.NORTH,
            GridBagConstraints.NONE,
            new Insets(10,20,30,20), 0, 0));

    this.getContentPane().add(TName,
        new GridBagConstraints(1, 0, 1, 1, 100.0, 0.0
            ,GridBagConstraints.NORTH,
            GridBagConstraints.HORIZONTAL,
            new Insets(10,20,30,20), 0, 0));


    this.getContentPane().add(jLabel2,
        new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.NORTH,
            GridBagConstraints.NONE,
            new Insets(0,20,0,0), 0, 0));

     // JScrollPane
    this.getContentPane().add(
            new JScrollPane(TEdit),
        new GridBagConstraints(
            0, 2, 2, 1, 100.0, 3000.0
            ,GridBagConstraints.EAST,
            GridBagConstraints.BOTH,
            new Insets(0,20,0,20), 0, 0));


     // JScrollPane
    this.getContentPane().add(
            new JScrollPane( new JTextArea()),
        new GridBagConstraints(
            0, 3, 2, 1, 100.0, 3000.0
            ,GridBagConstraints.EAST,
            GridBagConstraints.BOTH,
            new Insets(30,20,0,20), 0, 0));


   // --------------------------
            // Schalter
     JPanel panelBn = new JPanel();
     panelBn.setLayout( new FlowLayout() );
     panelBn.setBackground(Color.green);

    this.getContentPane().add(panelBn,
        new GridBagConstraints(0, 4, 2, 1, 100.0, 0.0
            ,GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(40,20,20,20), 0, 0));


    panelBn.add(BnOk);
    panelBn.add(BnEsc);

  jLabel1.setFont( new Font("Arial", Font.BOLD,18)  );
  jLabel2.setFont( new Font("Arial", Font.BOLD,18)  );
  TEdit.setFont( new Font("Arial", Font.BOLD,18)  );
  BnOk.setFont( new Font("Arial", Font.BOLD,18)  );
  BnEsc.setFont( new Font("Arial", Font.BOLD,18)  );
  } // setGUI



  void BnEsc_Clicked() {
    System.exit(0);
  }


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

}


