Swing Größe von JLabels verändern sich in einem Panel unterschiedlich

SilencerandLois

Aktives Mitglied
Hallo,
ich habe ein Panel, mit mehreren JLabels nebeneinander angeordnet. Wenn ich nun das Panel im Clientbetrieb in die Breite ziehe, wird nur der Eintrag ganz rechts vergrößert. Die anderen bleiben gleich. ICh möchte aber, dass alle Labels gleich groß werden. Die Labels sind auch alle gleich konfiguriert (Min-, Max- und Preffered-Size).

Danke für eure Hilfe!
lg
Martin
 
Hmmm, ich habe meine Glaskugel heute zu Hause gelassen, wie wäre es wenn du uns mal ein wenig Code zeigst 😉 ? Weil so ist es ein wenig schwer den fehler zu finden.
 
Glaskugel daheim vergessen, nicht gut ;-)

Zum Code: der Code wird duch den JForm-Designer der IDE IntelliJ automatisch generiert. Stammt also nur indirekt von mir. Das Panel heißt mJPanelPEInfo und wird in einem anderen Panel eingebettet (dieser Code ist nicht dabei, weil das zuviel des Guten wäre)

Java:
mJPanelPEInfo.setBorder(new TitledBorder("Detail-Informationen"));
mJPanelPEInfo.setName("jPanelPEInfo");
mJPanelPEInfo.setLayout(new GridBagLayout());
((GridBagLayout)mJPanelPEInfo.getLayout()).columnWidths = new int[] {0, 101, 77, 0, 0};
((GridBagLayout)mJPanelPEInfo.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)mJPanelPEInfo.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 1.0E-4};
((GridBagLayout)mJPanelPEInfo.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

//---- mLabel10 ----
mLabel10.setText("Atom-ID");
mJPanelPEInfo.add(mLabel10, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 5), 0, 0));
mJPanelPEInfo.add(mTextField1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 5), 0, 0));

//---- mLabel1 ----
mLabel1.setText("Eintrag-ID");
mJPanelPEInfo.add(mLabel1, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 5), 0, 0));
mJPanelPEInfo.add(mTextField7, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 0), 0, 0));

//---- mLabel9 ----
mLabel9.setText("Kurzname");
mJPanelPEInfo.add(mLabel9, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 5), 0, 0));
mJPanelPEInfo.add(mTextField2, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 5), 0, 0));

//---- mLabel3 ----
mLabel3.setText("Sortierwert 1");
mJPanelPEInfo.add(mLabel3, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 5), 0, 0));
mJPanelPEInfo.add(mTextField4, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 0), 0, 0));

//---- mLabel8 ----
mLabel8.setText("Langname");
mJPanelPEInfo.add(mLabel8, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 5), 0, 0));
mJPanelPEInfo.add(mTextField3, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 5), 0, 0));

//---- mLabel4 ----
mLabel4.setText("Sortierwert 2");
mJPanelPEInfo.add(mLabel4, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 5), 0, 0));
mJPanelPEInfo.add(mTextField5, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 0), 0, 0));

//---- mLabel2 ----
mLabel2.setText("W\u00e4hlbar");
mJPanelPEInfo.add(mLabel2, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 5), 0, 0));
mJPanelPEInfo.add(mCheckBox1, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(0, 0, 5, 0), 0, 0));

//---- mJLabelPEBemerkung ----
mJLabelPEBemerkung.setText("Bemerkung");
mJLabelPEBemerkung.setName("jLabelPEBemerkung");
mJPanelPEInfo.add(mJLabelPEBemerkung, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0,
  GridBagConstraints.WEST, GridBagConstraints.NONE,
  new Insets(1, 1, 6, 6), 0, 0));

//======== mJScrollPanePEBemerkung ========
{
  mJScrollPanePEBemerkung.setMinimumSize(new Dimension(200, 50));
  mJScrollPanePEBemerkung.setName("jScrollPanePEBemerkung");
  mJScrollPanePEBemerkung.setPreferredSize(new Dimension(200, 100));

  //---- mJTextAreaPEBemerkung ----
  mJTextAreaPEBemerkung.setLineWrap(true);
  mJTextAreaPEBemerkung.setRows(3);
  mJTextAreaPEBemerkung.setWrapStyleWord(true);
  mJTextAreaPEBemerkung.setName("jTextAreaPEBemerkung");
  mJScrollPanePEBemerkung.setViewportView(mJTextAreaPEBemerkung);
}
mJPanelPEInfo.add(mJScrollPanePEBemerkung, new GridBagConstraints(1, 5, 3, 2, 1.0, 1.0,
  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(1, 1, 1, 1), 0, 0));

Danke für die Hilfe!

lg
Martin
 
Konnte das Problem nun nach langem hin und her nun doch selber lesen.

Anscheinend war die Spaltengröße beim Gridbaglayout unterschiedlich konfiguriert. Ist mir zuerst wegen dem JFormDesigner-Editor nicht wirklich aufgefallen.
 

Neue Themen


Zurück
Oben