Unterschiede
Hier werden die Unterschiede zwischen der gewählten und der aktuellen Version gezeigt.
en:swing:gridbaglayout 2012/09/24 16:29 | en:swing:gridbaglayout 2020/01/22 21:00 aktuell | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | [[awt:awt|AWT]] | + | [[en:swing:swing|Java - AWT/Swing]]\\ |
====== GridBagLayout ====== | ====== GridBagLayout ====== | ||
Again and again you hear that the GridBagLayout is so complicated. It is really very extensive, but as a general rule you only need a few methods. | Again and again you hear that the GridBagLayout is so complicated. It is really very extensive, but as a general rule you only need a few methods. | ||
Zeile 27: | Zeile 27: | ||
\\ | \\ | ||
\\ | \\ | ||
- | **example**\\ | + | **Example**\\ |
- | The desires dialogue:\\ | + | The desired dialogue:\\ |
{{:gridbaglayout.gif|}}\\ | {{:gridbaglayout.gif|}}\\ | ||
\\ | \\ | ||
Zeile 35: | Zeile 35: | ||
| 0,1 | 1,1 | | | 0,1 | 1,1 | | ||
- | Die Liste auf der linken Seite belegt also die beiden Gitterfelder 0,0 und 0,1. | + | The list on the left side situated the two grid arrays 0,0 and 0,1. |
- | Die Höhe der Liste beträgt somit "2". Um einem Control (hier der Liste) die Positions- und Größenangaben zuzuordnen, wird die Klasse GridBagConstraints verwendet.\\ | + | Therefore, the height of the list is "2". To assign a control (here of the list) to details of position and height, the class GridBagConstraints is used.\\ |
- | Der dazugehörige Source sieht so aus: | + | The go with it source looks like this: |
<code java> | <code java> | ||
Zeile 56: | Zeile 56: | ||
GridBagConstraints gbc=new GridBagConstraints(); | GridBagConstraints gbc=new GridBagConstraints(); | ||
- | // Festlegen, dass die GUI-Elemente die Gitterfelder in | + | // Determine, that the GUI-elements fill out |
- | // waagerechter Richtung ausfüllen: | + | // the grid arrays in horizontal direction: |
gbc.fill=GridBagConstraints.HORIZONTAL; | gbc.fill=GridBagConstraints.HORIZONTAL; | ||
- | // Die Abstände der einzelnen GUI-Elemente zu den gedachten | + | // Determine the distances of the single |
- | // Gitterlinien festgelegen: | + | // GUI-elements to the thought grid lines: |
gbc.insets = new Insets(2,2,2,2); | gbc.insets = new Insets(2,2,2,2); | ||
- | gbc.gridx = 0; // x-Position im gedachten Gitter | + | gbc.gridx = 0; // x-position in the thought grid |
- | gbc.gridy = 0; // y-Position im gedachten Gitter | + | gbc.gridy = 0; // y-position in the thought grid |
- | gbc.gridheight = 2; // zwei Gitter-Felder hoch | + | gbc.gridheight = 2; // two grid-arrays high |
List list = new List(3); | List list = new List(3); | ||
gbl.setConstraints(list, gbc); | gbl.setConstraints(list, gbc); | ||
Zeile 74: | Zeile 74: | ||
gbc.gridy=0; | gbc.gridy=0; | ||
gbc.gridheight = 1; | gbc.gridheight = 1; | ||
- | Label label = new Label("Nur eine Demo"); | + | Label label = new Label("Only a demo"); |
gbl.setConstraints(label, gbc); | gbl.setConstraints(label, gbc); | ||
add(label); | add(label); | ||
Zeile 81: | Zeile 81: | ||
gbc.gridy=1; | gbc.gridy=1; | ||
gbc.gridheight = 1; | gbc.gridheight = 1; | ||
- | btClose = new Button("Schließen"); | + | btClose = new Button("close"); |
btClose.addActionListener(this); | btClose.addActionListener(this); | ||
gbl.setConstraints(btClose, gbc); | gbl.setConstraints(btClose, gbc); | ||
Zeile 103: | Zeile 103: | ||
- | Natürlich hat das GridBagLayout noch mehr Möglichkeiten. | + | Of course, GridBagLayout has more possibilities as well. |
- | Häufig verwendet werden auch noch die GridBagConstraints-Parameter | + | GridBagConstraints-parameter are also used often, too. |
weightx | weightx | ||
- | und | + | and |
weighty | weighty | ||
. | . | ||
- | Diese können Werte zwischen 0.0 und 1.0 einnehmen und geben an, wie der verbleibende Freiraum aufgeteilt wird. | + | These can take values between 0.0 and 1.0 and indicate how the lingering freedom will be divided up. |
- | Beispiel: Ein Dialog habe eine verfügbare Breite von 600 Pixeln. In diesem Dialog seien zwei Elemente A und B angeordnet. Dabei habe Element A ein minimalen Platzbedarf von 300 Pixeln und Element B einen minimalen Platzbedarf von 100 Pixeln. Damit bleiben 200 Pixel über. Diese werden im Verhältnis der beiden Werte für weightx aufgeteilt. Angenommen Element A habe ein weightx von 0.75 und Element B ein weigtx von 0.25, so wird das Gitterfeld für A eine Breite von 450 Pixeln (300+0.75*200) und Gitterfeld B eine Breite von 150 (100+0.25*200) Pixeln erhalten. | + | Example: A dialogue has an available width of 600 pixel. There are laid out two elements A and B in this dialogue. With it, element A has a minimal place requirement of 300 pixel and element B has a minimal place requirement of 100 pixel. Therefore, there are 200 pixel left. These are divided up for weightx proportional to both values. Assuming that element A has a weightx of 0.75 and element B a weightx of 0.25, the grid field for A will contain a width of 450 pixel (300+0.75*200) and the grid field B will contain a width of 150 (100+0.25*200). |
- | Wird ergänzt... | + | To be continued... |