Abstände und Zeilenangaben im GridBagLayout

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Abstände und Zeilenangaben im GridBagLayout

    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)

    Quellcode

    1. public class QuotationTemplate extends JDialog implements ActionListener{
    2. JPanel content;
    3. JTextField templateName, templatePreview;
    4. JComboBox[] fields;
    5. JButton[] bConfigure;
    6. JButton addField, save, cancel;
    7. public QuotationTemplate() {
    8. this.setTitle("Create a new quotation template");
    9. this.setLocation(250, 130);
    10. this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    11. this.setupContent();
    12. this.pack();
    13. this.setVisible(true);
    14. }
    15. private void setupContent(){
    16. //setup main container
    17. this.content = new JPanel();
    18. this.content.setLayout(new GridBagLayout());
    19. GridBagConstraints c = new GridBagConstraints();
    20. //template name label
    21. JLabel nameL = new JLabel("Template name");
    22. c.fill = GridBagConstraints.NONE;
    23. c.weightx = 0.5;
    24. c.gridx = 0;
    25. c.gridy = 0;
    26. c.ipadx = 5;
    27. content.add(nameL);
    28. //template name field
    29. this.templateName = new JTextField(15);
    30. c.fill = GridBagConstraints.NONE;
    31. c.weightx = 0.5;
    32. c.gridwidth = 1;
    33. c.gridx = 1;
    34. c.gridy = 0;
    35. content.add(templateName);
    36. //add field button
    37. this.addField = new JButton("add field");
    38. c.fill = GridBagConstraints.NONE;
    39. c.weightx = 0.5;
    40. c.gridwidth = 1;
    41. c.gridx = 2;
    42. c.gridy = 0;
    43. content.add(addField);
    44. //dropdowns and configure buttons
    45. this.fields = new JComboBox[11];
    46. for(int i = 0; i <= 10; i++){
    47. fields[i] = new JComboBox();
    48. fields[i].addItem("CB");
    49. c.fill = GridBagConstraints.NONE;
    50. c.weightx = 0.5;
    51. c.weighty = 0.5;
    52. c.gridwidth = 1;
    53. c.gridx = 0;
    54. c.gridy = i+1;
    55. content.add(fields[i]);
    56. }
    57. //test
    58. JButton bla = new JButton("test");
    59. c.gridx = 0;
    60. c.gridy = 20;
    61. content.add(bla);
    62. //add content to mainframe
    63. this.add(content);
    64. }
    65. }
    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 :)