Hallo,
ich habe einen JDialog, in dem verschiedene Elementen untereinander angeordnet werden sollen.
Das Problem ist, dass die Elemente beim Ausführen alle in eine einzige Zeile gepackt werden, obwohl ich GridBagContraints.gridy jeweils angegeben habe.
[Blockierte Grafik: http://img88.imageshack.us/img88/7200/49576422pv1.png]
Eigentlich sollte nach dem "Add field" Knopf eine neue Zeile beginnen und dann jede ComboBox auch in eine eigene Zeile.
Ich bin ratlos.
Hier der Quelltext (sehr simpel)
Alles anzeigen
Was mich auch noch stört ist, dass das Label und das Textfeld (im source die beiden ersten Elemente) wie aneinander geklebt sind, obwohl ich da auch GridBagConstraints.ipadx angegeben habe, was doch eigentlich einen horizontalen Abstand machen sollte, oder?
Vielen Dank schon im Voraus für Antworten :)
ich habe einen JDialog, in dem verschiedene Elementen untereinander angeordnet werden sollen.
Das Problem ist, dass die Elemente beim Ausführen alle in eine einzige Zeile gepackt werden, obwohl ich GridBagContraints.gridy jeweils angegeben habe.
[Blockierte Grafik: http://img88.imageshack.us/img88/7200/49576422pv1.png]
Eigentlich sollte nach dem "Add field" Knopf eine neue Zeile beginnen und dann jede ComboBox auch in eine eigene Zeile.
Ich bin ratlos.
Hier der Quelltext (sehr simpel)
Quellcode
- public class QuotationTemplate extends JDialog implements ActionListener{
- JPanel content;
- JTextField templateName, templatePreview;
- JComboBox[] fields;
- JButton[] bConfigure;
- JButton addField, save, cancel;
- public QuotationTemplate() {
- this.setTitle("Create a new quotation template");
- this.setLocation(250, 130);
- this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
- this.setupContent();
- this.pack();
- this.setVisible(true);
- }
- private void setupContent(){
- //setup main container
- this.content = new JPanel();
- this.content.setLayout(new GridBagLayout());
- GridBagConstraints c = new GridBagConstraints();
- //template name label
- JLabel nameL = new JLabel("Template name");
- c.fill = GridBagConstraints.NONE;
- c.weightx = 0.5;
- c.gridx = 0;
- c.gridy = 0;
- c.ipadx = 5;
- content.add(nameL);
- //template name field
- this.templateName = new JTextField(15);
- c.fill = GridBagConstraints.NONE;
- c.weightx = 0.5;
- c.gridwidth = 1;
- c.gridx = 1;
- c.gridy = 0;
- content.add(templateName);
- //add field button
- this.addField = new JButton("add field");
- c.fill = GridBagConstraints.NONE;
- c.weightx = 0.5;
- c.gridwidth = 1;
- c.gridx = 2;
- c.gridy = 0;
- content.add(addField);
- //dropdowns and configure buttons
- this.fields = new JComboBox[11];
- for(int i = 0; i <= 10; i++){
- fields[i] = new JComboBox();
- fields[i].addItem("CB");
- c.fill = GridBagConstraints.NONE;
- c.weightx = 0.5;
- c.weighty = 0.5;
- c.gridwidth = 1;
- c.gridx = 0;
- c.gridy = i+1;
- content.add(fields[i]);
- }
- //test
- JButton bla = new JButton("test");
- c.gridx = 0;
- c.gridy = 20;
- content.add(bla);
- //add content to mainframe
- this.add(content);
- }
- }
Was mich auch noch stört ist, dass das Label und das Textfeld (im source die beiden ersten Elemente) wie aneinander geklebt sind, obwohl ich da auch GridBagConstraints.ipadx angegeben habe, was doch eigentlich einen horizontalen Abstand machen sollte, oder?
Vielen Dank schon im Voraus für Antworten :)