Java Tutorial 47 (GUI) – GridBagLayout and GridBagConstraints

///Java Tutorial 47 (GUI) – GridBagLayout and GridBagConstraints

Java Tutorial 47 (GUI) – GridBagLayout and GridBagConstraints

FavoriteLoadingAdd to favorites

In this Java tutorial, you’ll learn how to make a custom layout by using the GridBagLayout and GridBagConstraints.

source

Java468x60
By |2020-10-06T09:47:23+00:00October 6th, 2020|Java Video Tutorials|20 Comments

20 Comments

  1. Clash With Tim October 6, 2020 at 9:47 am - Reply

    Very helpful video. make it in 1.5x though

  2. amadeu joaquim October 6, 2020 at 9:47 am - Reply

    Melhor vdeo com este conteudo que ja vi…..
    Muito obrigado

  3. Franck Sgen Lecroyant October 6, 2020 at 9:47 am - Reply

    Cool bro! Thank you so much! I finally understand the things of gridWidth and gridHeight, insets and fill. God Bless you so much! You are just amazing at explaining things in a very simple and efficient way!

  4. DoodooButt October 6, 2020 at 9:47 am - Reply

    1.75 speed

  5. LEGOSI October 6, 2020 at 9:47 am - Reply

    does it work only with buttons.
    Asking because cant make it work

  6. Mesut Uluag October 6, 2020 at 9:47 am - Reply

    thanks for help

  7. DefinitelyNot October 6, 2020 at 9:47 am - Reply

    public void setPositionAdd(Component c, int gridx, int gridy) {

    gbc.gridx = gridx;

    gbc.gridy = gridy;

    mainPanel.add(c,gbc);

    }

  8. Aafiq Bukhari October 6, 2020 at 9:47 am - Reply

    this tutorial may be 8 years old but ty for saving me

  9. badees abood October 6, 2020 at 9:47 am - Reply

    thank you so much it helped me alot

  10. Lymey October 6, 2020 at 9:47 am - Reply

    Thanks! The grid bag layout is peculiar, especially in regards to setting the width/height on components. I appreciate the straightforward tutorial to clear things up.

  11. john houser October 6, 2020 at 9:47 am - Reply

    I wish you would have talked about the FIRST_LINE_END, LINE_END,…. and such. Those don't seem to work the way they are described. I have a JFrame using BorderLayout and add JPanel classes that use GridBagLayouts. I can't get the rows and columns to work right.

  12. Matthew Oxford October 6, 2020 at 9:47 am - Reply

    Heres the whole code: import java.awt.GridBagConstraints;

    import java.awt.GridBagLayout;

    import java.awt.Insets;

    import javax.swing.JButton;

    import javax.swing.JFrame;

    import javax.swing.JPanel;

    public class Tutorial extends JPanel

    {

    JButton b1, b2, b3, b4, b5;

    GridBagConstraints gbc = new GridBagConstraints();

    public Tutorial2()

    {

    setLayout(new GridBagLayout());

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

    b1 = new JButton("Button1");

    gbc.gridx = 0;

    gbc.gridy = 0;

    gbc.gridheight = 5;

    gbc.fill = GridBagConstraints.VERTICAL;

    add(b1, gbc);

    b2 = new JButton("Button2");

    gbc.gridx = 1;

    gbc.gridy = 1;

    gbc.gridheight = 1;

    add(b2, gbc);

    b3 = new JButton("Button3");

    gbc.gridx = 2;

    gbc.gridy = 2;

    gbc.gridheight = 1;

    add(b3, gbc);

    b4 = new JButton("Button4");

    gbc.gridx = 3;

    gbc.gridy = 3;

    gbc.gridheight = 1;

    add(b4, gbc);

    b5 = new JButton("Button5");

    gbc.gridx = 1;

    gbc.gridy = 4;

    gbc.gridheight = 1;

    gbc.gridwidth = 3;

    gbc.fill = GridBagConstraints.HORIZONTAL;

    add(b5, gbc);

    }

    public static void main(String[] args)

    {

    Tutorial t = new Tutorial();

    JFrame jf = new JFrame();

    jf.setTitle("Tutorial");

    jf.setSize(500, 500);

    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    jf.setVisible(true);

    jf.add(t);

    }

    }

  13. Afif Khaja October 6, 2020 at 9:47 am - Reply

    Great tutorial. 11:00 gbc.gridheight = 5 means that the height of button 1 should be 5 cells [0, 0 to 0, 4] but it is only showing up in 4 cells [0, 1 to 0, 4]. Why isn't button 1 showing up in cell 0,0?

  14. ArbitraryP October 6, 2020 at 9:47 am - Reply

    Why is everything at the center of the Panel … How to do you compress the layout so that it is not centered??

  15. Afif Khaja October 6, 2020 at 9:47 am - Reply

    GREAT video. I think gridbaglayout is the best option for buttons but it is a little complex. This video was of the perfect complexity and length

  16. Genosse RedCat [Proletariat.ch] October 6, 2020 at 9:47 am - Reply

    Very good Tutorial! Thank you very much.

  17. Hugo González October 6, 2020 at 9:47 am - Reply

    Thanks so much. Regards from Zapopan, México. :')

  18. Vincent Oostelbos October 6, 2020 at 9:47 am - Reply

    At double speed, this was quite watchable. Thank you for this tutorial on the absolute basics of GridBagLayout. I'll need more to be able to properly use it, but it's a good start.

  19. władek eb110 October 6, 2020 at 9:47 am - Reply

    I've seen several tutorials about GribBagLayouts but this is the very first one which explains weigh and fill credentials in proper way. Thanks a lot.

  20. Yusuf Bulent Avci October 6, 2020 at 9:47 am - Reply

    Good tutorial. In speed 1.5

Leave A Comment

*