J
java_starter2008
Gast
hi,
ich sitze gerad vor einem Layoutproblem.
Mit dem Code möchte ich folgende JButtons-Anordnung erreichen.
Bild
wie schaffe ich das ? bitte um eure Hilfe
danke
ich sitze gerad vor einem Layoutproblem.
Code:
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JFrame;
public class GUI extends JFrame{
Container con;
GridBagConstraints gbConst ;
final static int ANZHAL= 14 ;
int i=0;
JButton[] mulde_btns= new JButton[ANZHAL];
GUI(String title) {
super(title);
con = this.getContentPane();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
con.setLayout(new GridBagLayout());
this.setSize(850, 400);
this.setLocation(170, 100);
gbConst = new GridBagConstraints();
this.setVisible(true);
//gbConst.insets = new Insets(50,0,0,0); //Padding
mulde_btns[0] = new JButton("Dummy1");
gbConst.fill = GridBagConstraints.HORIZONTAL;
gbConst.weightx = 0;
gbConst.weighty = 0;
gbConst.gridx = 0;
gbConst.gridy = 0;
//gbConst.gridheight= 4;
mulde_btns[0].setPreferredSize(new Dimension(100,200));
con.add(mulde_btns[0],gbConst);
mulde_btns[1] = new JButton("Button1");
gbConst.fill = GridBagConstraints.HORIZONTAL;
gbConst.weightx = 0;
gbConst.weighty = 0;
gbConst.gridx = 1;
gbConst.gridy = 0;
mulde_btns[1].setPreferredSize(new Dimension(100,100));
con.add(mulde_btns[1],gbConst);
mulde_btns[2] = new JButton("Button1");
gbConst.fill = GridBagConstraints.HORIZONTAL;
gbConst.weightx = 0;
gbConst.weighty = 0;
gbConst.gridx = 2;
gbConst.gridy = 0;
mulde_btns[2].setPreferredSize(new Dimension(100,100));
con.add(mulde_btns[2],gbConst);
mulde_btns[3] = new JButton("Button1");
gbConst.fill = GridBagConstraints.HORIZONTAL;
gbConst.weightx = 0;
gbConst.weighty = 0;
gbConst.gridx = 3;
gbConst.gridy = 0;
mulde_btns[3].setPreferredSize(new Dimension(100,100));
con.add(mulde_btns[3],gbConst);
mulde_btns[4] = new JButton("Button1");
gbConst.fill = GridBagConstraints.HORIZONTAL;
gbConst.weightx = 0;
gbConst.weighty = 0;
gbConst.gridx = 4;
gbConst.gridy = 0;
mulde_btns[4].setPreferredSize(new Dimension(100,100));
con.add(mulde_btns[4],gbConst);
mulde_btns[5] = new JButton("Button1");
gbConst.fill = GridBagConstraints.HORIZONTAL;
gbConst.weightx = 0;
gbConst.weighty = 0;
gbConst.gridx = 5;
gbConst.gridy = 0;
mulde_btns[5].setPreferredSize(new Dimension(100,100));
con.add(mulde_btns[5],gbConst);
mulde_btns[6] = new JButton("Button1");
gbConst.fill = GridBagConstraints.HORIZONTAL;
gbConst.weightx = 0;
gbConst.weighty = 0;
gbConst.gridx = 6;
gbConst.gridy = 0;
mulde_btns[6].setPreferredSize(new Dimension(100,100));
con.add(mulde_btns[6],gbConst);
mulde_btns[7] = new JButton("Dummy");
gbConst.fill = GridBagConstraints.HORIZONTAL;
gbConst.weightx = 0;
gbConst.weighty = 0;
gbConst.gridx = 7;
gbConst.gridy = 0;
//gbConst.gridheight= 4;
mulde_btns[7].setPreferredSize(new Dimension(100,100));
con.add(mulde_btns[7],gbConst);
mulde_btns[8] = new JButton("Button1");
gbConst.fill = GridBagConstraints.HORIZONTAL;
gbConst.weightx = 0;
gbConst.weighty = 0;
gbConst.gridx = 1;
gbConst.gridy = 1;
mulde_btns[8].setPreferredSize(new Dimension(100,200));
con.add(mulde_btns[8],gbConst);
}
}
Mit dem Code möchte ich folgende JButtons-Anordnung erreichen.
Bild
wie schaffe ich das ? bitte um eure Hilfe
danke