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 JPanel createTextComponentPane(String labelText, JTextComponent textComp, Font font,
        Color bgColor, boolean isVertical) {
    JPanel outPane = new JPanel();
    outPane.setLayout(new BorderLayout());
    outPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    JLabel labelOut = new JLabel(labelText, SwingConstants.LEFT);
    if (isVertical) {
        outPane.add(labelOut, BorderLayout.NORTH);
    } else {/*  w  ww .j  a  v a  2  s  . c om*/
        outPane.add(labelOut, BorderLayout.WEST);
    }
    if (textComp instanceof JTextArea) {
        outPane.add(createScrollPane((JTextArea) textComp, font, bgColor), BorderLayout.CENTER);
    } else {
        textComp.setBackground(bgColor);
        textComp.setFont(font);
        outPane.add(textComp, BorderLayout.CENTER);
    }
    return outPane;
}

From source file:AlignX.java

private static Container makeIt(String labelChar, float alignment) {
    JPanel container = new JPanel();
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);

    for (int i = 1; i < 6; i++) {
        String label = makeLabel(labelChar, i * 2);
        JButton button = new JButton(label);
        button.setAlignmentX(alignment);
        container.add(button);// w  ww . ja v a  2s. c om
    }
    return container;
}

From source file:Main.java

public static JPanel createPainelContainer(String title, Component... components) {
    JPanel panel = createPainelContainer(title, null, components);
    panel.setLayout(new BoxLayout(panel, 0));

    return panel;
}

From source file:Main.java

public static JPanel getPanelFlowLayoutHorizontal(int w, int h, int type) {
    JPanel panel = new JPanel();
    FlowLayout layout = new FlowLayout();
    layout.setAlignment(type);// www .  j  a v a  2  s .c o m
    panel.setLayout(layout);
    panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    panel.setPreferredSize(getControlDimension(w, h));
    panel.setMinimumSize(getControlDimension(w, h));
    return panel;
}

From source file:Main.java

/**
 * Creates a labeled panel containing a slider and considering
 * a particular width/*from ww  w.  j av  a  2 s . c  o m*/
 * 
 * @param slider
 * @param label
 * @return a panel for the slider
 */
public static JPanel createSliderPanel(final JSlider slider, String label, int width) {
    final JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.setBorder(new TitledBorder(label));
    p.setPreferredSize(new Dimension(width, 60));
    p.add(slider);
    return p;
}

From source file:Main.java

/**
 * @param title//from w  w  w.  j  a v a 2  s. co m
 * @param comp 
 * @return jpanel
 */
public static JPanel createTitledScrollComponent(String title, Component comp) {
    JScrollPane scroll = new JScrollPane(comp);
    scroll.setWheelScrollingEnabled(true);
    scroll.setPreferredSize(new Dimension(1, 1));
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createTitledBorder(title));
    panel.setLayout(new BorderLayout());
    panel.add(scroll, BorderLayout.CENTER);
    return panel;
}

From source file:Main.java

/** 
 * Creates a <code>JPanel</code> containing the given text placed in the
 * center as the only component./* w w w  .j ava  2  s.  c om*/
 * @param text - the text to put on the panel
 * @return a JPanel containing only the given text
 */
public static JPanel makeTextPanel(String text) {
    JPanel panel = new JPanel(false);
    JLabel filler = new JLabel(text);
    filler.setHorizontalAlignment(SwingConstants.CENTER);
    panel.setLayout(new GridLayout(1, 1));
    panel.add(filler);
    return panel;
}

From source file:Main.java

/**
 * 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
 *//*from w w w . j av  a  2  s .c  om*/
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;
}

From source file:XAxisAlignY.java

private static Container layoutComponents(String title, float alignment) {
    String labels[] = { "-", "-", "-" };

    JPanel container = new JPanel();
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS);
    container.setLayout(layout);
    for (int i = 0, n = labels.length; i < n; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentY(alignment);
        container.add(button);/*from w w w .j a  v  a  2 s  . c  o  m*/
    }
    return container;
}

From source file:YAxisAlignX.java

private static Container layoutComponents(String title, float alignment) {
    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);

    for (int i = 0, n = labels.length; i < n; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentX(alignment);
        container.add(button);// www  . j a v  a 2  s.  co m
    }
    return container;
}