Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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 createVertical(final Component... components) {
        final JPanel jp = new JPanel(new GridBagLayout());
        final GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(0, 5, 4, 5);
        gbc.anchor = GridBagConstraints.NORTH;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        for (final Component component : components) {
            if (gbc.gridy == components.length - 1) {
                gbc.weighty = 1.0;
            }
            jp.add(component, gbc);
            gbc.gridy++;
        }
        return jp;
    }
}