Java Swing BoxLayout xBoxLayoutPanel(Component... components)

Here you can find the source of xBoxLayoutPanel(Component... components)

Description

Return new JPanel with the specified components laid out in a BoxLayout along the X-axis

License

Open Source License

Parameter

Parameter Description
components components to place in JPanel

Return

new JPanel

Declaration

public static JPanel xBoxLayoutPanel(Component... components) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;

import java.awt.LayoutManager;

import javax.swing.BoxLayout;
import javax.swing.JPanel;

public class Main {
    /**/*from w  ww .ja v  a 2  s. c o  m*/
     * Return new JPanel with the specified components laid out in a BoxLayout along the X-axis
     * @param components components to place in JPanel
     * @return new JPanel
     */
    public static JPanel xBoxLayoutPanel(Component... components) {
        return newJPanel(BoxLayout.X_AXIS, components);
    }

    private static JPanel newJPanel(int layoutAxis, Component... components) {
        JPanel retval = new JPanel();
        retval.setLayout(new BoxLayout(retval, layoutAxis));
        for (Component component : components)
            retval.add(component);
        return retval;
    }

    /**
     * Return new JPanel with specified LayoutManager, containing specified components
     * @param layoutManager layout manager to use
     * @param components components to place into panel
     * @return new JPanel with specified LayoutManager, containing specified components
     */
    public static JPanel newJPanel(LayoutManager layoutManager, Component... components) {
        JPanel retval = new JPanel();
        retval.setLayout(layoutManager);
        for (Component component : components)
            retval.add(component);
        return retval;
    }
}

Related

  1. newBox(String name, String... items)
  2. newBoxForComponent(Component c)
  3. show(JComponent comp, String windowName)
  4. show(JComponent component)
  5. vbox(Component c1, Component c2)