//Titel:            Dialog-Fenster
//Version:
//Copyright:		Copyright (c) 2010
//Autor:
//Organisation:
//Beschreibung:


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


public class test_Caret extends JFrame {

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

  JButton BnOk = new JButton("Ok");
  JButton BnSetCaret = new JButton("SetCaret");


  private JPanel jpanel;


  public test_Caret() {
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setSize(400, 430);
    setTitle("JFrame als Dialog");
    setGUI();
  }

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

    BnOk.setFont( new Font("Arial", Font.BOLD,18)  );
    BnSetCaret.setFont( new Font("Arial", Font.BOLD,18)  );
    BnOk.setPreferredSize( BnSetCaret.getPreferredSize() );

    jLabel1.setText("Name");
    TName.setText("Frau Kreuzmann");

    jLabel2.setText("Vorname");
    TName2.setText("Petra");

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



    this.getContentPane().add(jLabel1,
         new GridBagConstraints(
             0, 0, 1, 1, 20.0, 0.0
            ,GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(10,25,40,0), 0, 0));

    this.getContentPane().add(TName,
        new GridBagConstraints(
               1, 0, 1, 1, 80.0, 0.0
            ,GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(10,25,40,25), 0, 0));


    this.getContentPane().add(jLabel2,
         new GridBagConstraints(
             0, 1, 1, 1, 20.0, 0.0
            ,GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0,25,40,0), 0, 0));

    this.getContentPane().add(TName2,
        new GridBagConstraints(
             1, 1, 1, 1, 80.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
            new Insets(0,25,40,25), 0, 0));



    JPanel pn = new JPanel();
    pn.add(BnOk);
    pn.add(BnSetCaret);
//    pn.setBackground(Color.green);
    this.getContentPane().add(pn,
           new GridBagConstraints(0, 2, 2, 1, 1.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
            new Insets(0,0,0,0), 0, 0));


      BnOk.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
          BnOk_Click();
        }
      });


      BnSetCaret.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
          BnSetCaret_Click();
        }
      });


  } // setGUI

    private void BnOk_Click() {
        System.out.println("Hier in Ok");
    }

    private void BnSetCaret_Click() {
       TName.requestFocus();
		TName.setCaretPosition(0);
    }



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

}  // test_Caret


