javax.swing.GroupLayout stretches JPanel



  • There's JPanel in it, JLabel, JLabel, JTextArea, JButton.

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(panel);
            panel.setLayout(layout);
    
        layout.setHorizontalGroup(layout.createParallelGroup()
                .addGroup(layout.createSequentialGroup()
                        .addComponent(icon)
    
                        .addGroup(layout.createParallelGroup()
                            .addComponent(text)
                            .addComponent(but1)
                        )
    
    
                )
        );
    
        layout.setVerticalGroup(layout.createParallelGroup()
                .addGroup(layout.createParallelGroup()
                        .addComponent(icon)
    
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(text)
                            .addComponent(but1)
                        )
    
    
                )
        );
    

    The text is JTextArea, stretching out for some reason completely on the top of the panel on which it is located and it's the ephect.

    http://joxi.ru/brR6opxhQY33Mr

    And if you add other panels, it's fine, how can you fix it?

    http://joxi.ru/D2PQo0nudkaa7A



  • I've got it all figured out.

    layout.setVerticalGroup(layout.createParallelGroup()
                    .addGap(10)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
    
                        .addComponent(icon)
    
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(text)
                            .addComponent(but1)
                        )
    
    
                )
                .addGap(10)
        );
    


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2