Hallo,
ich möchte zwei Label (4.Reihe) hintereinander auf ein Panel zeichnen. Die Labels sind wie alle anderen Komponenten mit dem GridBagLayout angeordnet.
Mein Problem ist jetzt, dass ich die Länge der Label auf der horizontalen (x-Achse) nicht einstellen kann - sie ist immer so wie die der vorigen Konponenten (0.5 bei den Buttons).
Egal welche Werte ich bei weightx eintrage, es ändert sich nchts.
Woran liegt das?
[HIGHLIGHT="Java"]private void initPanelButton() {
getPanelButton();
/* 1. row */
addComponent(pnlButton, gbl, getButtonSave(), 0, 0, 1, 1, 1, 0.5, 0.0, new Insets(0, 0, 1, 1));
addComponent(pnlButton, gbl, getButtonDelete(), 1, 0, 1, 1, 1, 0.5, 0.0, new Insets(0, 0, 1, 0));
/* 2. row */
addComponent(pnlButton, gbl, getButtonBackward(), 0, 1, 1, 1, 1, 0.5, 0.0, new Insets(0, 0, 1, 1));
addComponent(pnlButton, gbl, getButtonForward(), 1, 1, 1, 1, 1, 0.5, 0.0, new Insets(0, 0, 1, 0));
/* 3. row*/
addComponent(pnlButton, gbl, getButtonReset(), 0, 2, 2, 1, 1, 1.0, 0.0, null);
/* 4. row */
addComponent(pnlButton, gbl, getLabelErrSucc(), 0, 3, 1, 1, GridBagConstraints.HORIZONTAL, 0.0, 0.0, null);
addComponent(pnlButton, gbl, getLabelInformation(), 1, 3, 1, 1, GridBagConstraints.HORIZONTAL, 0.0, 0.0, null);
}[/HIGHLIGHT]
[HIGHLIGHT="Java"]private static void addComponent(
final Container cont,
final GridBagLayout gbl,
final Component component,
final int gridx,
final int gridy,
final int gridwidth,
final int gridheight,
final int fill,
final double weightx,
final double weighty,
final Insets insets) {
final GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = gridx;
gbc.gridy = gridy;
gbc.gridwidth = gridwidth;
gbc.gridheight = gridheight;
gbc.fill = fill;
gbc.weightx = weightx;
gbc.weighty = weighty;
if (insets != null)
{ gbc.insets = insets; }
gbl.setConstraints(component, gbc);
cont.add(component);
}[/HIGHLIGHT]
ich möchte zwei Label (4.Reihe) hintereinander auf ein Panel zeichnen. Die Labels sind wie alle anderen Komponenten mit dem GridBagLayout angeordnet.
Mein Problem ist jetzt, dass ich die Länge der Label auf der horizontalen (x-Achse) nicht einstellen kann - sie ist immer so wie die der vorigen Konponenten (0.5 bei den Buttons).
Egal welche Werte ich bei weightx eintrage, es ändert sich nchts.
Woran liegt das?
[HIGHLIGHT="Java"]private void initPanelButton() {
getPanelButton();
/* 1. row */
addComponent(pnlButton, gbl, getButtonSave(), 0, 0, 1, 1, 1, 0.5, 0.0, new Insets(0, 0, 1, 1));
addComponent(pnlButton, gbl, getButtonDelete(), 1, 0, 1, 1, 1, 0.5, 0.0, new Insets(0, 0, 1, 0));
/* 2. row */
addComponent(pnlButton, gbl, getButtonBackward(), 0, 1, 1, 1, 1, 0.5, 0.0, new Insets(0, 0, 1, 1));
addComponent(pnlButton, gbl, getButtonForward(), 1, 1, 1, 1, 1, 0.5, 0.0, new Insets(0, 0, 1, 0));
/* 3. row*/
addComponent(pnlButton, gbl, getButtonReset(), 0, 2, 2, 1, 1, 1.0, 0.0, null);
/* 4. row */
addComponent(pnlButton, gbl, getLabelErrSucc(), 0, 3, 1, 1, GridBagConstraints.HORIZONTAL, 0.0, 0.0, null);
addComponent(pnlButton, gbl, getLabelInformation(), 1, 3, 1, 1, GridBagConstraints.HORIZONTAL, 0.0, 0.0, null);
}[/HIGHLIGHT]
[HIGHLIGHT="Java"]private static void addComponent(
final Container cont,
final GridBagLayout gbl,
final Component component,
final int gridx,
final int gridy,
final int gridwidth,
final int gridheight,
final int fill,
final double weightx,
final double weighty,
final Insets insets) {
final GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = gridx;
gbc.gridy = gridy;
gbc.gridwidth = gridwidth;
gbc.gridheight = gridheight;
gbc.fill = fill;
gbc.weightx = weightx;
gbc.weighty = weighty;
if (insets != null)
{ gbc.insets = insets; }
gbl.setConstraints(component, gbc);
cont.add(component);
}[/HIGHLIGHT]