Hallo,
ich ärgere mich gerade etwas mit dem GridBagLayout und zwar sieht meine GUI ohne JComboBox so aus:
und mit:
Ich bin absolut ratlos wie ich das beheben kann, wisst ihr wo ran das liegen kann?
Schon mal danke für eure Hilfe.
GUI:
GridBagLayoutHelper :
ich ärgere mich gerade etwas mit dem GridBagLayout und zwar sieht meine GUI ohne JComboBox so aus:

und mit:

Ich bin absolut ratlos wie ich das beheben kann, wisst ihr wo ran das liegen kann?
Schon mal danke für eure Hilfe.
GUI:
PHP:
public class Test {
public Test(){
JFrame f = new JFrame();
f.setSize(840, 710);
JPanel pUpdatePackage=new JPanel();
pUpdatePackage.setLayout(new BorderLayout(0,0));
JTextField tfOld = new JTextField(12);
JTextField tfNew = new JTextField(12);
int tfLongLength=31;int spaceToEdge=10;
JTextField tfClientIds= new JTextField(tfLongLength);
JLabel lNew = new JLabel("Neue Versionsnummer");
JLabel lOld = new JLabel("Aktuelle Versionsnummer");
JLabel lIds = new JLabel("IDs");
JPanel pGeneral=new JPanel();
pGeneral.setPreferredSize(new Dimension(20,170));
GridBagLayoutHelper grid=new GridBagLayoutHelper(GridBagConstraints.WEST);
pGeneral.setLayout(grid);
pGeneral.setBorder(new EmptyBorder(0,spaceToEdge+4,0,0));
JPanel p=new JPanel();
p.add(tfOld);
grid.addComponent(pGeneral, lOld, 0, 0, 1, 1, 0, 0);
grid.addComponent(pGeneral, p, 1, 0, 1, 1, 1, 0) ;
p=new JPanel();
p.add(tfNew);
grid.addComponent(pGeneral, lNew, 0 ,1, 1, 1, 0, 0) ;
grid.addComponent(pGeneral, p, 1, 1, 1, 1, 0, 0) ;
p=new JPanel();
p.add(tfClientIds);
grid.addComponent(pGeneral, lIds, 0 ,2, 1, 1, 0, 0) ;
grid.addComponent(pGeneral, p, 1 ,2, 1, 1, 0, 0) ;
JPanel pDestiny=new JPanel();
pDestiny.setLayout(new FlowLayout(FlowLayout.LEFT));
JLabel lDestiny=new JLabel("Zielordner");
JTextField tfDestiny= new JTextField();
tfDestiny.setColumns(tfLongLength);
JButton changeDestiny=new JButton("...");
pDestiny.add(tfDestiny);
pDestiny.add(changeDestiny);
grid.addComponent(pGeneral, lDestiny, 0 ,3, 1,1, 0, 0) ;
grid.addComponent(pGeneral, pDestiny, 1 ,3, 1, 1, 0, 0) ;
JLabel lUrl=new JLabel("URL");
JTextField tfUrl= new JTextField();
tfUrl.setColumns(tfLongLength);
p=new JPanel();
p.add(tfUrl);
grid.addComponent(pGeneral, lUrl, 0 ,4, 1, 1, 0, 0) ;
grid.addComponent(pGeneral, p, 1 ,4, 1, 1, 0, 0) ;
JCheckBox rootId=new JCheckBox();
rootId.setText("Allgemeines Update erstellen");
//grid.addComponent(pGeneral, rootId, 0 ,5, 2, 1, 0, 0) ;
pUpdatePackage.add(pGeneral,BorderLayout.NORTH);
f.add(pUpdatePackage);
f.setVisible(true);
}
public static void main(String[] args) {
Test t= new Test();
}
}
PHP:
public class GridBagLayoutHelper extends GridBagLayout{
private int anchor;
private Insets insets;
public GridBagLayoutHelper(int anchor){
super();
this.anchor=anchor;
insets=new Insets(0,0,0,0);
}
public GridBagLayoutHelper(){
this(GridBagConstraints.WEST);
}
public void addComponent( Container cont,Component c,
int x, int y,int width, int height,
double weightx, double weighty )
{
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = x; gbc.gridy = y;
gbc.gridwidth = width; gbc.gridheight = height;
gbc.weightx = weightx; gbc.weighty = weighty;
gbc.anchor = anchor;
gbc.insets=insets;
this.setConstraints( c, gbc );
cont.add( c );
}
public void setInsets(int top, int left, int bottom, int right){
insets=new Insets(top,left,bottom,right);
}
}