get Swing Component With Margin and return JPanel - Java Swing

Java examples for Swing:JComponent

Description

get Swing Component With Margin and return JPanel

Demo Code


//package com.java2s;
import java.awt.Component;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JPanel;

public class Main {
    public static JPanel getComponentWithMargin(Component component,
            int top, int left, int bottom, int right) {
        JPanel ret = new JPanel(new GridBagLayout());
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.weightx = 1.0;//from   ww  w.  j  av a 2s .c om
        constraints.weighty = 1.0;
        constraints.fill = GridBagConstraints.BOTH;
        constraints.insets = new Insets(top, left, bottom, right);
        ret.add(component, constraints);
        return ret;
    }
}

Related Tutorials