tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
1
ZUGRIFFE
355
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    HeinerPyt HeinerPyt ist offline Mitglied Gold
    Registriert seit
    Nov 2003
    Beiträge
    180
    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
     

  2. #2
    Daniel Traub Daniel Traub ist offline Rookie
    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

  1. Probleme mit GridBagLayout
    Von Futzel im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 1
    Letzter Beitrag: 27.04.10, 16:25
  2. GridBagLayout probleme
    Von Tithilion im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 2
    Letzter Beitrag: 22.08.08, 07:59
  3. GridBagLayout
    Von MScalli im Forum Java
    Antworten: 3
    Letzter Beitrag: 15.02.08, 10:15
  4. Probleme mit dem GridBagLayout
    Von schnuffie im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 12
    Letzter Beitrag: 06.02.06, 09:45
  5. Probleme mit GridBagLayout und JScrollPane
    Von Romsl im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 5
    Letzter Beitrag: 02.08.05, 23:18