Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright 2001-2008 Aqris Software AS. All rights reserved.
 * 
 * This program is dual-licensed under both the Common Development
 * and Distribution License ("CDDL") and the GNU General Public
 * License ("GPL"). You may elect to use one or the other of these
 * licenses.
 */

import javax.swing.JComponent;

import javax.swing.JPanel;

import java.awt.BorderLayout;

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

public class Main {
    /**
     * Creates a panel that contains all of the components on top of each other in north,
     * and tries to make them as small as possible (probably by using getPreferredSize()).
     *
     * @deprecated use proper layout, usually no need to use such complex/ugly layouting
     */
    public static JPanel combineInNorth(JComponent[] components) {
        JPanel result = new JPanel();
        if (components.length == 0) {
            return result;
        }
        result.setLayout(new BorderLayout());
        JPanel contentPanel = new JPanel();
        result.add(contentPanel, BorderLayout.NORTH);
        contentPanel.setLayout(new GridBagLayout());

        GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.weightx = 1.0;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        for (int i = 0; i < components.length; i++) {
            contentPanel.add(components[i], constraints);
        }
        if (result.isVisible())
            result.doLayout();
        return result;
    }
}