passendes Layout gesucht

Status
Nicht offen für weitere Antworten.

KalleWirsch

Aktives Mitglied
Hallo zusammen,

ich versuche mit Java ein Layout zu erstellen das so aussieht wie das im Anhang.
Allerdings ist es mir nicht gelungen es mit zum Beispiel dem GridBagLayout und anderen die für Java 1.4 funktionieren darzustellen. Das dass Textfield in der zweiten Spalte genau in der Mitte der oberen zwei Textfields liegen soll scheint ein dickes Problem zu sein.

Bis jetzt hab ich nur ein passendes Layout gefunden und zwar das GroupLayout welches der NetBeans GuiBuilder benutzt. Allerdings kann ich nicht ohne weiteres die jar hierfür in mein Projekt einbinden.

Kennt jemand eine Lösung hierfür? Ich dachte eigentlich das mit dem GridBagLayout so gut wie alles möglich wäre. Aber ich habe klappte sogar mit GuiBuilder aller Jvider (in der Trialversion) nicht das gewünschte Ergebnis zu erzielen.

viele Grüße!!
 

Anhänge

  • form.jpg
    form.jpg
    9,4 KB · Aufrufe: 52
Mit GridBagLayout geht das schon. Nur musst du Schönheitskomponenten (Komponenten die keinen Sinn haben aber für das Aussehen des Layouts relevant sind) verwenden.

Ich habs mal nicht getestet aber sollte das gewünschte Ergebniss erzielen

Code:
addComponentInLayout(panel1,
                0, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER,
                0.0, 0.0, new Insets(7,7,7,7));

addComponentInLayout(Schönheitspanel,
                1, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER,
                0.0, 0.0, new Insets(7,7,7,7));

addComponentInLayout(panel2,
                 2, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER,
                 0.0, 0.0, new Insets(7,7,7,7));

addComponentInLayout(Schönheitspanel,
                  3, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER,
                  0.0, 0.0, new Insets(7,7,7,7));

addComponentInLayout(panel3,
                4, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER,
                0.0, 0.0, new Insets(7,7,7,7));

addComponentInLayout(Schönheitspanel,
                 5, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER,
                 0.0, 0.0, new Insets(7,7,7,7));

addComponentInLayout(panel4,
                  6, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER,
                  0.0, 0.0, new Insets(7,7,7,7));

addComponentInLayout(panel1Unten,
                   0, 1, 3, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER,
                   0.0, 0.0, new Insets(7,7,7,7));

addComponentInLayout(panel2Unten,
                    4, 1, 3, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER,
                    0.0, 0.0, new Insets(7,7,7,7));


/**
     * Setzt die uebergebene Componente entsprechend den Constraintparametern
     * in das Gridbaglayout des Panels ein.
     *
     *
     * @param aComponent javax.swing.JComponent
     * @param aGridX int
     * @param aGridY int
     * @param aGridWidth int
     * @param aGridHeight int
     * @param aFillConstraint int
     * @param anAnchorConstraint int
     * @param aWeightX int
     * @param aWeightY int
     * @param anInsets java.awt.Insets
     */
    protected void addComponentInLayout(
        JComponent aComponent,
        int aGridX,
        int aGridY,
        int aGridWidth,
        int aGridHeigth,
        int aFillConstraint,
        int anAnchorConstraint,
        double aWeightX,
        double aWeightY,
        Insets anInsets) {

        GridBagConstraints theConstraint = new GridBagConstraints();

        theConstraint.gridx = aGridX;
        theConstraint.gridy = aGridY;
        theConstraint.gridwidth = aGridWidth;
        theConstraint.gridheight = aGridHeigth;
        theConstraint.fill = aFillConstraint;
        theConstraint.anchor = anAnchorConstraint;
        theConstraint.weightx = aWeightX;
        theConstraint.weighty = aWeightY;
        theConstraint.insets = anInsets;

        this.add(aComponent, theConstraint);

    }
 
okay! Super, danke für die Hilfe!!

Ich habe mich jetzt aber doch dem GroupLayout bedient. Da es zumindest diesen Zweck doch ziemlich einfach zu gebrauchen war.

grazie und viele Grüße!
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben