GridBagLayout, vermutlich Resize-Problem

Layna

Erfahrenes Mitglied
Hallo.
Ok, ich kämpfe hier ein wenig mit dem GridBagLayout.
Da das alles etwas schwerer zu erklären ist, guckt euch mal bitte die Screenshots an.
Beim ersten Bild funktioniert noch alles normal, so soll es (zumindest in etwa) aussehen.
In Bild zwei habe ich lediglich die FesnterBREITE verändert. WARUm wird meine TextArea jetzt verkleinert?
Kann ich das GridBagLayout irgendwie davon überzeugen der Textarea IMMER ihre Höhe einzuräumen?

Das GridBagLyout hat standardässig:
Code:
inputHolder.setLayout(new GridBagLayout());
inputHolder.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
GridBagConstraints c = new GridBagConstraints();
c.weightx = 0.5;
c.weighty = 0.5;

Für die TextArea setzte ich:
Code:
c.gridwidth = GridBagConstraints.REMAINDER;

Hoffe jemand kann mir helfen.
Ciao
Larayna
 

Anhänge

  • passt.GIF
    passt.GIF
    16,3 KB · Aufrufe: 67
  • passtnicht.GIF
    passtnicht.GIF
    14,9 KB · Aufrufe: 57
Aus der API:

public GridBagConstraints(int gridx,
int gridy,
int gridwidth,
int gridheight,
double weightx,
double weighty,
int anchor,
int fill,
Insets insets,
int ipadx,
int ipady)

Creates a GridBagConstraints object with all of its fields set to the passed-in arguments. Note: Because the use of this constructor hinders readability of source code, this constructor should only be used by automatic source code generation tools.

Parameters:
gridx - The initial gridx value.
gridy - The initial gridy value.
gridwidth - The initial gridwidth value.
gridheight - The initial gridheight value.
weightx - The initial weightx value.
weighty - The initial weighty value.

anchor - The initial anchor value.
fill - The initial fill value.
insets - The initial insets value.
ipadx - The initial ipadx value.
ipady - The initial ipady value.

Also z.B.
Code:
contentPane.add(jpMyPanel,      new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
						,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), 0, 0));
bedeutet, dass die Komponente jpMyPanel an der Stelle 0,0 im Grid mit einer Ausdehung von jeweils 1 Zelle in x- und y-Richtung, einer Gewichtung von 1.0 (also max) in x- und y-Richtung, eine Verankerung oben links (NORTHWEST) und eine Ausdehnung in x- und y-Richtung (BOTH) der contentPane hinzugefügt wird.
Also wenn eine Komponente den meisten Raum bekommen soll, muss sie 1.0/1.0 und GridBagConstraints.BOTH gesetzt bekommen.
 
Ah, so ist es schon besser, Danke :).
So ganz langsam sieht die Oberfläche so aus wie sie soll... nur langsam, aber es wird!
 
Ein Tip noch:
Je nach Anzahl und Komplexität der GUI empfiehlt es sich, mit mehreren Panels zu arbeiten. Z.B. ein Panel unten für die Standard-Buttons "Schliessen", "Abbruch", "OK" usw.
 
Zurück