ERLEDIGT
NEIN
NEIN
ANTWORTEN
1
1
ZUGRIFFE
355
355
EMPFEHLEN
-
Hallo ich habe folgenden Code:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
static void addComponent( Panel cont, GridBagLayout gbl, Component c, int x, int y, int width, int height, double weightx, double weighty) { GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = width; gbc.gridheight = height; gbc.weightx = weightx; gbc.weighty = weighty; gbl.setConstraints( c, gbc ); cont.add( c ); } . . . . . public void main() { final JFrame win = new bodenwert(600,300); win.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); win.setTitle("Berechnet den Bodenwert"); Panel panel1 = new Panel(); panel1.setSize(300, 300); GridBagLayout GBL = new GridBagLayout(); panel1.setLayout(GBL); panel1.setForeground(Color.MAGENTA); addComponent(panel1, GBL ,new JLabel("Grundstücksgröße"), 0, 1, 0, 0, 1.0, 0 ); addComponent(panel1, GBL ,new JLabel("Hinterlandgrösse"), 0, 2, 0, 0, 0,0 ); addComponent(panel1, GBL ,new JLabel("Vorderlandgrösse"), 0, 3, 0, 0, 1.0,0 ); addComponent(panel1, GBL ,Tgesamtgroesse, 1, 0, 0, 0, 0,0 ); win.add(panel1); win.setVisible( true ); }
Wenn ich dies ausführe werden alle Komponenten an einer Stelle übereinander dargestellt. Wenn ch bei jeder Komponente die entsprechenden Angaben (gridx, gridy, etc.) seperat mache dann funktioniert es.
Hat jemand eine Ahnung woran es liegen kann, dass ich die einzelnen Labels nicht untereinander dargestellt bekomme?
Danke
Heiner
-
03.12.10 10:16 #2
- Registriert seit
- Nov 2010
- Beiträge
- 6
Das liegt vermutlich daran, dass alle Komponenten null höhe und null breite haben.
// posX posY width height weightX weightY
addComponent(panel1, GBL ,new JLabel("Grundstücksgröße"), 0, 1, 1, 1, 1.0, 0 );
Ähnliche Themen
-
Probleme mit GridBagLayout
Von Futzel im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 1Letzter Beitrag: 27.04.10, 16:25 -
GridBagLayout probleme
Von Tithilion im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 2Letzter Beitrag: 22.08.08, 07:59 -
GridBagLayout
Von MScalli im Forum JavaAntworten: 3Letzter Beitrag: 15.02.08, 10:15 -
Probleme mit dem GridBagLayout
Von schnuffie im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 12Letzter Beitrag: 06.02.06, 09:45 -
Probleme mit GridBagLayout und JScrollPane
Von Romsl im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 5Letzter Beitrag: 02.08.05, 23:18





Zitieren
Login





