Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

GridBagLayout

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

ich hab Probleme mit dem GridBagLayout. Schaut euch mal folgendes Listing an:

class Test extends JPanel {

public Test() {

GridBagLayout gbl = new GridBagLayout();

setLayout(gbl);

GridBagConstraints gbc;

JLabel test1 = new JLabel("Test");

gbc = makegbc(0,0,2,1);

gbl.setConstraints(test1, gbc);

add(test1);

JTextField test2 = new JTextField(200);

gbc = makegbc(0,1,1,2);

gbc.weightx = 100;

gbl.setConstraints(test2, gbc);

add(test2);

JButton test3 = new JButton("Holdrio");

gbc = makegbc(3,0,1,2);

gbl.setConstraints(test3, gbc);

add(test3);

this.setVisible(true);

}

private GridBagConstraints makegbc(int x, int y, int width, int height) {

GridBagConstraints gbc = new GridBagConstraints();

gbc.gridx = x;

gbc.gridy = y;

gbc.gridwidth = width;

gbc.gridheight = height;

gbc.insets = new Insets(1,1,1,1);

return gbc;

}

}

Dieses Panel wird hinterher in einem JFrame angezeigt. Das Problem ist das das JTextField test2 immer superschmal angezeigt wird, also praktisch nur ein Strich ist, obwohl ich es mit

JTextField test2 = new JTextField(200);

instanziere, es also 200 Zeichen breit sein müsste. Was mach ich falsch, bzw. wie kann ich es hinkriegen das das Textfeld eine vernünftige Breite hat?

Danke im voraus....

Hallo,

der Effekt passiert wenn das JTextField(200) nicht genügend Platz auf im zugehörigen Container hat.

Wieso muss das JTextField 200 Zeichen lang sein, wie willst du das darstellen?

Falls es trotzdem gewollt ist, musst du halt das Panel vergrößern oder auf eine JScrollPane packen.

Gruß Jaraz

Ups, 200 war wohl was viel, mit 20 gehts. *vordenkopfschlag* :rolleyes:

Ich war irritiert, weil ichs zunächst mit new JTextField() instanziert habe, da hab ich eigentlich gedacht es würde von haus aus auf ne normale größe festegelegt sein, aber auch da war es nur ein Strich.

Naja, danke auf jeden Fall

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.