Example usage for javax.swing JPanel setLayout

List of usage examples for javax.swing JPanel setLayout

Introduction

In this page you can find the example usage for javax.swing JPanel setLayout.

Prototype

public void setLayout(LayoutManager mgr) 

Source Link

Document

Sets the layout manager for this container.

Usage

From source file:Main.java

public static void getPanelGridLayout(JPanel panel, int rows, int cols) {
    panel.setLayout(new GridLayout(rows, cols, 1, 1));
}

From source file:Main.java

/**
 * @return a new panel whose layout forces the original panel to shrink in
 *         size as much as possible.//from   w ww  .  ja  v a  2  s  .co m
 */
public static JPanel wrapInMinimizer(JPanel panel) {
    JPanel result = new JPanel();
    result.setLayout(new BorderLayout());
    result.add(panel, BorderLayout.WEST);

    return result;
}

From source file:Main.java

private static final Component group(final Component[] components, final int axis) {
    final JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, axis));

    for (final Component component : components) {
        panel.add(component);//from  w ww .j  av a  2s . c o m
    }

    return panel;
}

From source file:Main.java

public static JPanel createVerticalPanel(Component topCmp, Component centerCmp) {
    JPanel outPane = new JPanel();
    outPane.setLayout(new BorderLayout());
    outPane.setBorder(new EmptyBorder(5, 5, 5, 5));

    outPane.add(topCmp, BorderLayout.NORTH);
    outPane.add(centerCmp, BorderLayout.CENTER);

    return outPane;
}

From source file:Main.java

public static JPanel getComponentColumn(JComponent[] components) {
    JPanel columnPanel = new JPanel();
    columnPanel.setLayout(new BoxLayout(columnPanel, BoxLayout.PAGE_AXIS));

    for (int i = 0; i < components.length; i++) {
        components[i].setMinimumSize(new Dimension(components[i].getPreferredSize().width, ROW_HEIGHT));
        components[i].setPreferredSize(new Dimension(components[i].getPreferredSize().width, ROW_HEIGHT));
        components[i].setMaximumSize(new Dimension(components[i].getPreferredSize().width, ROW_HEIGHT));
        components[i].setAlignmentX(JComponent.LEFT_ALIGNMENT);
        columnPanel.add(components[i]);/*w w  w  .  j av  a 2s .  com*/
    }
    return columnPanel;
}

From source file:QandE.Layout3.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread.//from  ww w  . j av a2s  .  c  o  m
 */
private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("Layout3");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Add the innards.
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
    p.add(createComponent("Component 1"));
    p.add(Box.createVerticalGlue());
    p.add(createComponent("Component 2"));
    p.add(createComponent("Component 3"));
    p.add(createComponent("Component 4"));
    frame.setContentPane(p);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

/**
 * @param panel//from   w ww .j  a  va  2  s  .  c om
 * @return pre-configured constraints
 */
public static GridBagConstraints initPanel(JPanel panel) {
    panel.setLayout(new GridBagLayout());
    panel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    GridBagConstraints gb = new GridBagConstraints();
    gb.gridx = 0;
    gb.gridy = 0;
    gb.insets = new Insets(2, 2, 2, 2);
    return gb;
}

From source file:Main.java

/** Make a JPanel with a horizontal {@link BoxLayout}. */
public static JPanel makeHorizontalBoxPanel() {
    JPanel result = new JPanel();
    result.setLayout(new BoxLayout(result, BoxLayout.X_AXIS));
    return result;
}

From source file:Main.java

/**
 * Puts an array of components into a new panel with a label.
 * //from   ww  w.j a va  2 s .  c  o  m
 * @param a
 *            The Components to add.
 * @param label
 *            The label of the panel.
 * @return A Panel with the given label and the components inside.
 */
public static JPanel addToLabeledPanel(Component[] a, String label) {
    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, a.length));
    addAll(a, panel);
    panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), label));
    return panel;
}

From source file:Main.java

public static void setupNowLoadingPanel(JPanel panel) {
    JLabel loading = new JLabel("Loading...", SwingConstants.CENTER);
    panel.setLayout(new BorderLayout());
    panel.add(loading, BorderLayout.CENTER);
    panel.revalidate();/*from ww  w.  j av a2s .c  o  m*/
    panel.repaint();
}