GridLayout - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.


vindeshvindesh Posts: 1Member
How to use GridBageLayout in java


  • zibadianzibadian Posts: 6,349Member
    : How to use GridBageLayout in java
    Call the Container.setLayout() of the container object, whose layout you want to change, and specify a GridLayout object. The GridLayout object can be made on the fly with new:
    MyApplet.setLayout(new GridLayout(3, 4));
    , or be stored in a variable. The parameters define the number of grid cells in x, y directions.
    Each component, which is added to the Container, is added row by row from top-left to bottom-right. Example:
    this.setLayout(new GridLayout(2, 2));
    produces a layout of:
    Label1 Label2

    Label3 Label4
    Additional settings like the spacing of the grid cells can be specified. See javadoc for more info on the variables/methods in GridLayout.
Sign In or Register to comment.