make GridBagConstraints - Java Swing

Java examples for Swing:GridBagLayout

Description

make GridBagConstraints

Demo Code


//package com.java2s;
import java.awt.GridBagConstraints;
import java.awt.Insets;

public class Main {
    public static GridBagConstraints makeGbc(int x, int y) {
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridwidth = 1;/*  w w  w . j av  a2 s. com*/
        gbc.gridheight = 1;
        gbc.gridx = x;
        gbc.gridy = y;
        gbc.weightx = x;
        gbc.weighty = 1.0;
        gbc.insets = new Insets(5, 5, 5, 5);
        gbc.anchor = (x == 0) ? GridBagConstraints.LINE_START
                : GridBagConstraints.LINE_END;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        return gbc;
    }
}

Related Tutorials