# Problem mit NetBeans



## Achim (9. Sep 2004)

Hi,

mache mit Netbeans eine kleine GUI..jetzt die Frage : ich habe 2 Panels ,also 2 Zeilen, in denen je 4 Texfields sind .
wie kann ich nun jeweils das zweite Textfeld von links zu einem geminsamen Textfeld zusammenführen.??

oder geht dies nur mit GridBagLayout ? wenn ja wie ? alles GridBagLayout ? oder die 2 Panles FlowLayout, und Frame GridBagLayout??
hab keine Ahnung wie ich das hinbekomme, außer mit dem NullLayout..

Danke


----------



## L-ectron-X (9. Sep 2004)

Schade, ich habe die Frage nicht ganz verstanden. Ein Bildchen vom Istzustand könnte helfen.
Bekommst Du das hin?


----------



## Achim (9. Sep 2004)

...hier der Code ..


```
/*
 * Test1.java
 *
 * Created on 9. September 2004, 18:39
 */

package Netbeans;


public class Test1 extends javax.swing.JFrame {
    
    /** Creates new form Test1 */
    public Test1() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();

        getContentPane().setLayout(new java.awt.FlowLayout());

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        jLabel1.setText("jLabel1");
        jPanel1.add(jLabel1);

        jButton1.setText("jButton1");
        jPanel1.add(jButton1);

        jButton2.setText("jButton2");
        jPanel1.add(jButton2);

        jButton3.setText("jButton3");
        jPanel1.add(jButton3);

        getContentPane().add(jPanel1);

        jLabel2.setText("jLabel2");
        jPanel2.add(jLabel2);

        jButton4.setText("jButton4");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jPanel2.add(jButton4);

        jButton5.setText("jButton5");
        jPanel2.add(jButton5);

        jButton6.setText("jButton6");
        jPanel2.add(jButton6);

        getContentPane().add(jPanel2);

        pack();
    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
    
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new Test1().show();
    }
    
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration
    
}
```


----------



## L-ectron-X (9. Sep 2004)

Hab mit mal den Code kompiliert. Weit und breit ist nichts von Textfeldern zu sehen.
Du verwendest zwei Labels und insgesamt 6 Buttons.
Sorry, ich kann Dir mit einer solchen Basis nicht helfen. Die Fragestellung lässt absolut keine Antwort zu. :roll: 
http://www.java-forum.org/de/viewtopic.php?t=8116


----------



## Achim (9. Sep 2004)

Sorry.. ich meinte natürlich Textfelder...eigentlich simple frage ???:L ..
es sind 2 Zeilen. .und ich möchte von der 1Zeile das 2.Texfeld von links, und von der 2.Zeile das 2.Textfeld von links
zusammenführen..ich hoffe die frage ist angekommen? ..ich habe dies Felder nun mit XXX gekennzeichnet..

Danke..nochmal..


```
package Netbeans;


public class Test1 extends javax.swing.JFrame {
    
    /** Creates new form Test1 */
    public Test1() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {
        panel1 = new java.awt.Panel();
        label1 = new java.awt.Label();
        textField1 = new java.awt.TextField();
        textField2 = new java.awt.TextField();
        textField3 = new java.awt.TextField();
        textField4 = new java.awt.TextField();
        panel2 = new java.awt.Panel();
        label2 = new java.awt.Label();
        textField5 = new java.awt.TextField();
        textField6 = new java.awt.TextField();
        textField7 = new java.awt.TextField();
        textField8 = new java.awt.TextField();

        getContentPane().setLayout(new java.awt.FlowLayout());

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        label1.setText("label1");
        panel1.add(label1);

        textField1.setText("textField1");
        panel1.add(textField1);

        textField2.setText("XXXX");
        panel1.add(textField2);

        textField3.setText("textField3");
        panel1.add(textField3);

        textField4.setText("textField4");
        panel1.add(textField4);

        getContentPane().add(panel1);

        label2.setText("label2");
        panel2.add(label2);

        textField5.setText("textField5");
        panel2.add(textField5);

        textField6.setText("XXXX");
        panel2.add(textField6);

        textField7.setText("textField7");
        panel2.add(textField7);

        textField8.setText("textField8");
        panel2.add(textField8);

        getContentPane().add(panel2);

        pack();
    }
    
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        Test1 test =new Test1();
      
        test.setSize(380,200);
        test.show();
    }
    
   
    
    
    
    // Variables declaration - do not modify
    private java.awt.Label label1;
    private java.awt.Label label2;
    private java.awt.Panel panel1;
    private java.awt.Panel panel2;
    private java.awt.TextField textField1;
    private java.awt.TextField textField2;
    private java.awt.TextField textField3;
    private java.awt.TextField textField4;
    private java.awt.TextField textField5;
    private java.awt.TextField textField6;
    private java.awt.TextField textField7;
    private java.awt.TextField textField8;
    // End of variables declaration
    
}
```


----------



## L-ectron-X (11. Sep 2004)

Sollte mit GridbagLayout möglich sein. In Netbeans lässt sich das GribagLayout sehr komfortabel einstellen.
Ich poste mal in Kürze den Code zu Deinem Beispiel.


----------



## L-ectron-X (12. Sep 2004)

```
public class Test1 extends javax.swing.JFrame {
    
    /** Creates new form Test1 */
    public Test1() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        jLabel1.setText("jLabel1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 0);
        getContentPane().add(jLabel1, gridBagConstraints);

        jLabel2.setText("jLabel2");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 0);
        getContentPane().add(jLabel2, gridBagConstraints);

        jTextField1.setText("jTextField1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 5);
        getContentPane().add(jTextField1, gridBagConstraints);

        jTextField2.setText("jTextField2");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 0);
        getContentPane().add(jTextField2, gridBagConstraints);

        jTextField3.setText("jTextField3");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 5);
        getContentPane().add(jTextField3, gridBagConstraints);

        jTextField4.setText("jTextField4");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 5);
        getContentPane().add(jTextField4, gridBagConstraints);

        jTextField5.setText("jTextField5");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        getContentPane().add(jTextField5, gridBagConstraints);

        jTextField6.setText("jTextField6");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        getContentPane().add(jTextField6, gridBagConstraints);

        jTextField7.setText("jTextField7");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 5);
        getContentPane().add(jTextField7, gridBagConstraints);

        pack();
    }
    
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new Test1().setVisible(true);
    }
    
    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    // End of variables declaration
    
}
```
Ich habs eben mal in 5 Minuten zusammen geklickt. Kopiere Dir mal den Quelltext und kompiliere ihn mal.
Sollte das Ganze so aussehen?


----------

