Probleme mit GridBagLayout

F

Futzel

Hi,

Ich habe versucht eine statisches Design in eine GridBagLayout umzuwandeln.
Leider habe ich Probleme mit der Anordung der einzelnen Komponenten.
Diese sind alle beim ausführen übereinander.

Hier mal der Code:

Java:
private JPanel getJContentPane() {
		if (jContentPane == null) {
		
			jContentPane = new JPanel();
			GridBagLayout gbl = new GridBagLayout();
			jContentPane.setLayout(gbl);
			GridBagConstraints c = new GridBagConstraints();
			
			jLabel_1 = new JLabel();
			c.gridx = 0;
			c.gridy = 0;
			c.gridwidth = 2;
			gbl.setConstraints(jLabel_1, c);
			jLabel_1.setBounds(new Rectangle(24, 16, 207, 18));
			jLabel_1.setText("Bitte wählen Sie ihre Programme");
			jContentPane.add(jLabel_1, null);
			
			
			c.fill = GridBagConstraints.BOTH;
			c.gridx = 0;
			c.gridy = 1;
			c.gridheight = 4;
			jList_GescannteProgramme = new JList();
			gbl.setConstraints(jList_GescannteProgramme, c);
			jContentPane.add(jList_GescannteProgramme, null);
			
			
			c.fill = GridBagConstraints.BOTH;
			c.gridx = 2;
			c.gridy = 1;
			c.gridheight = 4;
			jList_ConfigProgramme = new JList();
			gbl.setConstraints(jList_ConfigProgramme, c);
			jContentPane.add(jList_ConfigProgramme, null);
			
			c.gridx = 3;
			c.gridy = 2;
			c.gridheight = 2;
			c.anchor = GridBagConstraints.CENTER;
			jButton_Speichern = new JButton();
			gbl.setConstraints(jButton_Speichern, c);
			jContentPane.add(getJButton_Speichern(), null);
			
			
			c.gridx = 1;
			c.gridy = 1;
			c.anchor = GridBagConstraints.SOUTH;
			jButton_add = new JButton();
			gbl.setConstraints(jButton_add, c);
			jContentPane.add(getJButton_add(), null);
			
			c.gridx = 1;
			c.gridy = 4;
			c.anchor = GridBagConstraints.NORTH;
			jButton_remove = new JButton();
			gbl.setConstraints(jButton_remove, c);
			jContentPane.add(getJButton_remove(), null);
			
			
			c.gridx = 1;
			c.gridy = 2;
			c.fill = GridBagConstraints.BOTH;
			jButton_add_all = new JButton();
			gbl.setConstraints(jButton_add_all, c);
			jContentPane.add(getJButton_add_all(), null);
			
			c.gridx = 1;
			c.gridy = 3;
			c.fill = GridBagConstraints.BOTH;
			jButton_remove_all = new JButton();
			gbl.setConstraints(jButton_remove_all, c);
			jContentPane.add(getJButton_remove_all(), null);
			
			//pack();
		}
		return jContentPane;
	}

private JButton getJButton_Speichern() {
	
			jButton_Speichern.setText("Speichern");
			jButton_Speichern.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					if(datenConf.size() > 0)
					{
						tunerVar.setConf();	
						ProgrammDialog.renewConf();
						setVisible(false);
					}
					else
					{
						setVisible(false);
					}
				}});
		return jButton_Speichern;
	}

........
 
Also, wenn ich das GridBagLayout richtig verstanden habe, setzt du mit gridheight die horizontale Größe.
Wenn du nun also bei einer Komponenten gridy = 1 + gridheight = 6 setzt, solltest du logischerweise bei der zweiten Komponente gridy = 7 setzen!
Nimm lieber weighty = 6, da dies die Gewichtung gegenüber den anderen Komponenten festlegt.

Sollte ich es falsch verstanden habe, bitte ich um Korrektur!
 
Zurück