
// Beispiel mit GridBagLayout

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

import java.awt.event.*;

// Schalter mit FlowLayout 

public class GridBagLayout04b extends JFrame {

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

  JLabel jLabel2 = new JLabel();
  JTextField TMatrNr = new JTextField();
  JTextField TUNummer = new JTextField();

  JProgressBar jProgressBar1 = new JProgressBar();

  JButton BnUp = new JButton("Up");
  JButton BnDown = new JButton("Down");

  public GridBagLayout04b() {
    setSize(500, 300);
    setTitle("GridBagLayout04b. Beispiel (FlowLayout)");
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
  }

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

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

    jLabel2.setText("Nummern");
    TMatrNr.setText("(Matr.-Nr, 70%)");
    TUNummer.setText("(Unummer, 30%)");

    BnUp.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        BnUp_actionPerformed(e);
      }
    });
    BnDown.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        BnDown_actionPerformed(e);
      }
    });

    jProgressBar1.setMaximum(100);
    jProgressBar1.setMinimum(0);
    jProgressBar1.setValue( 15 );



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

    this.getContentPane().add(TName,
        new GridBagConstraints(1, 0, 2, 1, 100.0, 0.0
            ,GridBagConstraints.NORTH,
            GridBagConstraints.HORIZONTAL,
            new Insets(0,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));

    this.getContentPane().add(TMatrNr,
        new GridBagConstraints(1, 1, 1, 1, 70.0, 0.0
            ,GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0,20,0,0), 0, 0));

    this.getContentPane().add(TUNummer,
        new GridBagConstraints(2, 1, 1, 1, 30.0, 0.0
            ,GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0,20,0,20), 0, 0));


   // --------------------------
            // Progressbar
    this.getContentPane().add(jProgressBar1,
        new GridBagConstraints(0, 2, 3, 1, 100.0, 0.0
            ,GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(40,20,0,20), 0, 21));  //  21  zusätzliche Höhe


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

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


    panelBn.add(BnUp);
    panelBn.add(BnDown);
  } // setGUI


  void BnUp_actionPerformed(ActionEvent e) {
    jProgressBar1.setValue( jProgressBar1.getValue()+1 );
  }

  void BnDown_actionPerformed(ActionEvent e) {
    jProgressBar1.setValue( jProgressBar1.getValue()-1 );
  }


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


