Swing und GridbagLayout

steve77

Grünschnabel
Hallo alle miteinander, ich suche ein gutes beispiel für eine Swing GUI. Mich interessiert hierbei ganz besonders die Anordnung der einzelnen Elemente. Ich habe mich daran versucht, bekomme das aber leider nicht so ganz hin! Die GUI soll folgendes aussehen haben. 1 Label, 1 Combobox und dann ein Button. Dieses soll dann genauso auch noch mal darunter! Mein Code sieht zur Zeit folgender massen aus.



Code:
JPanel buttonPanel = createFilehandlerPanel();
		JPanel buttonPanel2 = createMessagehandlerPanel();
		GridBagLayout gbl = new GridBagLayout();
		setLayout(gbl);
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.anchor = GridBagConstraints.WEST;
		gbc.gridwidth = 1;

		int posY = 0;

		gbc.gridx = 0;
		gbc.gridy = posY++;
		gbc.weightx = 1;
		gbc.weighty = 1;
		gbc.fill = GridBagConstraints.BOTH;
		gbc.insets = new Insets(4, 4, 0, 4);
		gbc.gridx = 0;
		gbc.gridy = posY++;
		gbc.weightx = 0;
		gbc.weighty = 0;
		gbc.insets = new Insets(12, 4, 0, 4);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.CENTER;
		gbc.gridwidth = GridBagConstraints.REMAINDER;

		gbc.gridx = 0;
		gbc.gridy = posY++;
		gbc.insets = new Insets(12, 4, 0, 4);
		gbc.anchor = GridBagConstraints.CENTER;
		gbc.gridwidth = GridBagConstraints.REMAINDER;
		gbl.setConstraints(buttonPanel, gbc);
		add(buttonPanel);

		pack();
		setLocationRelativeToParent();
	}

	
	
	
	
	private JPanel createFilehandlerPanel() {
		JPanel aPanel = new JPanel();

		
//Filehandler
		
		JLabel label = new JLabel("Filehandler");
		JLabel label2 = new JLabel("RfcHandler");
		
		JComboBox combo1 = new JComboBox(comboStringsFilehandler);
	       combo1.setSelectedIndex(4);
	       combo1.addActionListener(this);
	       
	       GridBagLayout gbltest = new GridBagLayout();
			//aPanel.setLayout(gbl);
			GridBagConstraints gbctest = new GridBagConstraints();
			gbctest.anchor = GridBagConstraints.WEST;
			gbctest.fill = GridBagConstraints.NONE;
			gbctest.weightx = 0;
			gbctest.weighty = 0;
			gbctest.gridwidth = 3;
			gbctest.insets = new Insets(0, 6, 0, 6);
			aPanel.add(label);
			
			aPanel.add(combo1);

			
		GridBagLayout gbl = new GridBagLayout();
		aPanel.setLayout(gbl);
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.anchor = GridBagConstraints.WEST;
		gbc.fill = GridBagConstraints.NONE;
		gbc.weightx = 0;
		gbc.weighty = 1;
		gbc.gridwidth = 1;
		gbc.gridy = 0;

		 editButton = new PciButton("Edit","Edit", "edit", "",
					"", "", this, true, true, false, false, null, null);
		 newcpButton = new PciButton("newcp","newcp", "new cp", "",
					"", "", this, true, true, false, false, null, null);
		 newscratchButton = new PciButton("newscratch","newscratch", "new scratch", "",
					"", "", this, true, true, false, false, null, null);
		
		 
		gbc.gridx = 3;
		gbc.insets = new Insets(4, 4, 4, 4);
		gbl.setConstraints(editButton, gbc);
		aPanel.add(editButton);
		
		gbc.gridx = 4;
		gbc.insets = new Insets(4, 4, 4, 4);
		gbl.setConstraints(newcpButton, gbc);
		aPanel.add(newcpButton);
		
		gbc.gridx = 5;
		gbc.insets = new Insets(4, 4, 4, 4);
		gbl.setConstraints(newscratchButton, gbc);
		aPanel.add(newscratchButton);
		return aPanel;
	}

Ich bekomme es nicht hin, eine zweite Zeile mit genau den gleichen Elementen zu erzeugen!

vielen Dank schonmal für die Hilfe

Gruß
steve
 
Zurück