GridBag-Layout

Status
Nicht offen für weitere Antworten.

Alex_winf01

Top Contributor
Code:
JPanel reiter5 = new JPanel();
			reiter5.setBorder(rahmen);
			reiter5.setOpaque(true);
			reiter5.setBorder(new TitledBorder(new EtchedBorder(),"Seite 4"));
			
		 	GridBagLayout testverfahren_panel = new GridBagLayout();
		 	GridBagConstraints c = new GridBagConstraints();
		 	c.fill = GridBagConstraints.VERTICAL;
		 	
		 	JLabel objektive_testverfahren = new JLabel("04 objektive Testverfahren (z. B. CAT, Schwarzfuß, Sceno, TAT- oder Rorschach-Kurzform).........", JLabel.LEFT);
		 	c.weightx = 0.0;
		 	c.gridx = 0;
		 	c.gridy = 0;
		 	testverfahren_panel.setConstraints(objektive_testverfahren, c);
		 	reiter5.add(objektive_testverfahren);
		 	objektive_testverfahren_radioButton1 	= new JRadioButton("1 nein");
		 	c.weightx = 0.0;
		 	c.gridx = 0;
		 	c.gridy = 1;
		 	testverfahren_panel.setConstraints(objektive_testverfahren_radioButton1, c);
		 	reiter5.add(objektive_testverfahren_radioButton1);
		 	objektive_testverfahren_radioButton2 	= new JRadioButton("2 ja");
		 	c.weightx = 0.0;
		 	c.gridx = 0;
		 	c.gridy = 2;
		 	testverfahren_panel.setConstraints(objektive_testverfahren_radioButton2, c);
		 	reiter5.add(objektive_testverfahren_radioButton2);
		 	
		 	JLabel funktionstests = new JLabel("06 Funktions-, Konzentrations- oder Leistungstests (z. B. KTK, DRT, d2, HAWIE(K)-R, IST, K-ABC).........", JLabel.LEFT);
		 	//c.weightx = 0.0;
		 	c.gridx = 1;
		 	c.gridy = 0;
		 	testverfahren_panel.setConstraints(funktionstests, c);
		 	reiter5.add(funktionstests);
		 	funktionstests_radioButton1 = new JRadioButton("1 nein"); 
		 	testverfahren_panel.setConstraints(funktionstests_radioButton1, c);
		 	reiter5.add(funktionstests_radioButton1);
		 	c.gridx = 1;
		 	c.gridy = 1;
		 	funktionstests_radioButton2 = new JRadioButton("2 ja");
		 	c.gridx = 1;
		 	c.gridy = 2;
		 	testverfahren_panel.setConstraints(funktionstests_radioButton2, c);
		 	reiter5.add(funktionstests_radioButton2);

Das soll so aussehen:

04 objektive Testverfahren...........................1 nein 2 ja
06 Funktions-, Konzentrations......................1 nein 2 ja

Das Label 06 Funktions-, Konzentrations- oder Leistungstests (z. B. KTK, DRT, d2, HAWIE(K)-R, IST, K-ABC)......... hat dann doch den Wert 0,1 oder? Was mache ich da falsch?
 
das Layout heißt testverfahren_panel?

du hast dem Panel nicht das Layout zugewiesen,
+
x und y vertauscht,
+
teilweise die Constraints zugewiesen, bevor neue Koordinaten darin gesetzt wurden,

Tipp: schreibe dir eine Hilfsoperation und verwende
c = erstelleConstraints(0,0,0); // x, y, weightx
dann wird dein Code lesbarer..


Code:
public class TestGUI
    extends JFrame
{
    public TestGUI()
        throws Exception
    {
        JPanel reiter5 = new JPanel();

        GridBagLayout testverfahren_panel = new GridBagLayout();
        reiter5.setLayout(testverfahren_panel);
        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.VERTICAL;

        JLabel objektive_testverfahren = new JLabel(
                                                    "04 objektive Testverfahren (z. B. CAT, Schwarzfuß, Sceno, TAT- oder Rorschach-Kurzform).........",
                                                    JLabel.LEFT);
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.0;
        c.gridx = 0;
        c.gridy = 0;
        testverfahren_panel.setConstraints(objektive_testverfahren, c);
        reiter5.add(objektive_testverfahren);
        JRadioButton objektive_testverfahren_radioButton1 = new JRadioButton("1 nein");
        c.weightx = 0.0;
        c.gridx = 1;
        c.gridy = 0;
        testverfahren_panel.setConstraints(objektive_testverfahren_radioButton1, c);
        reiter5.add(objektive_testverfahren_radioButton1);
        JRadioButton objektive_testverfahren_radioButton2 = new JRadioButton("2 ja");
        c.weightx = 0.0;
        c.gridx = 2;
        c.gridy = 0;
        testverfahren_panel.setConstraints(objektive_testverfahren_radioButton2, c);
        reiter5.add(objektive_testverfahren_radioButton2);

        JLabel funktionstests = new JLabel(
                                           "06 Funktions-, Konzentrations- oder Leistungstests (z. B. KTK, DRT, d2, HAWIE(K)-R, IST, K-ABC).........",
                                           JLabel.LEFT);
        c.fill = GridBagConstraints.HORIZONTAL;
        // c.weightx = 0.0;
        c.gridx = 0;
        c.gridy = 1;
        testverfahren_panel.setConstraints(funktionstests, c);
        reiter5.add(funktionstests);
        JRadioButton funktionstests_radioButton1 = new JRadioButton("1 nein");
        c.gridx = 1;
        c.gridy = 1;
        testverfahren_panel.setConstraints(funktionstests_radioButton1, c);
        reiter5.add(funktionstests_radioButton1);
        JRadioButton funktionstests_radioButton2 = new JRadioButton("2 ja");
        c.gridx = 2;
        c.gridy = 1;
        testverfahren_panel.setConstraints(funktionstests_radioButton2, c);
        reiter5.add(funktionstests_radioButton2);


        getContentPane().add(reiter5);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(800, 400);
        setVisible(true);
    }

    public static void main(String[] args)
        throws Exception
    {
        new TestGUI();
    }
}
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben