Example usage for javax.swing JPanel setBorder

List of usage examples for javax.swing JPanel setBorder

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The component's border.")
public void setBorder(Border border) 

Source Link

Document

Sets the border of this component.

Usage

From source file:Main.java

public static JComponent scrollV(String title, JComponent content) {
    JPanel p = new JPanel(new BorderLayout());
    p.setBorder(BorderFactory.createTitledBorder(title));
    JScrollPane scroll = new JScrollPane(content);
    scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    p.add(scroll);//from w  w  w.  j a v  a2 s .co  m
    return p;
}

From source file:Main.java

public static JPanel createPainelContainer(String title, LayoutManager layout, Component... components) {
    final JPanel container = new JPanel();
    container.setBorder(BorderFactory.createTitledBorder(title));

    if (layout != null)
        container.setLayout(layout);//from   ww w.  ja v a  2s  .c o  m

    for (Component c : components) {
        container.add(c);
    }

    return container;

}

From source file:Main.java

/** Make a JPanel with a {@link BorderLayout}; set the border to the given margins. */
public static JPanel makeBorderPanel(int topMargin, int leftMargin, int bottomMargin, int rightMargin) {
    JPanel result = makeBorderPanel();
    result.setBorder(BorderFactory.createEmptyBorder(topMargin, leftMargin, bottomMargin, rightMargin));
    return result;
}

From source file:FactoryDemo.java

public static JPanel demo1() {
    // Demo 1: field with different formats with focus and without

    JPanel pan = new JPanel(new BorderLayout());
    pan.setBorder(new TitledBorder("Demo 1: format toggles with focus"));

    MaskFormatter withFocus = null, withoutFocus = null;
    try {/*w w  w  .  j  a va  2s .c o  m*/
        withFocus = new MaskFormatter("LLLL");
        withoutFocus = new MaskFormatter("UUUU");
    } catch (ParseException pe) {
    }

    DefaultFormatterFactory factory = new DefaultFormatterFactory(withoutFocus, null, withFocus);

    JFormattedTextField field = new JFormattedTextField(factory);
    field.setValue("Four");
    pan.add(field, BorderLayout.CENTER);

    return pan;
}

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

/** Make a JPanel with a horizontal {@link BoxLayout}; set the border to the given margins. */
public static JPanel makeHorizontalBoxPanel(int topMargin, int leftMargin, int bottomMargin, int rightMargin) {
    JPanel result = makeHorizontalBoxPanel();
    result.setBorder(BorderFactory.createEmptyBorder(topMargin, leftMargin, bottomMargin, rightMargin));
    return result;
}

From source file:Main.java

/**
 * @param panel//from ww w  . j a  v a  2 s  . co m
 * @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:FactoryDemo.java

public static JPanel demo2() {
    // Demo 2: Change the format of a field when the user presses a button.
    // We can't call field.setFormatter() because that's a protected method.
    // (Plus it wouldn't work anyway. The old factory would replace our new
    // formatter with an "old" one next time the field gains or loses
    // focus.)/*  ww w  .  j  a v  a 2s .co  m*/
    // The thing to do is send a new factory to field.setFormatterFactory().

    JPanel pan = new JPanel(new BorderLayout());
    pan.setBorder(new TitledBorder("Demo 2: change format midstream"));

    MaskFormatter lowercase = null;
    try {
        lowercase = new MaskFormatter("LLLL");
    } catch (ParseException pe) {
    }
    final JFormattedTextField field = new JFormattedTextField(lowercase);
    field.setValue("Fore");
    pan.add(field, BorderLayout.CENTER);

    final JButton change = new JButton("change format");
    JPanel changePanel = new JPanel();
    changePanel.add(change);
    pan.add(changePanel, BorderLayout.SOUTH);

    change.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            try {
                field.commitEdit(); // commit current edit (if any)
                MaskFormatter uppercase = new MaskFormatter("UUUU");
                DefaultFormatterFactory factory = new DefaultFormatterFactory(uppercase);
                field.setFormatterFactory(factory);
                change.setEnabled(false);
            } catch (ParseException pe) {
            }
        }
    });

    return pan;
}

From source file:Main.java

public static JPanel createFlow(final int align, final int gap, final Object... components) {
    final JPanel jp = new JPanel(new FlowLayout(align, gap, gap));
    jp.setBorder(BorderFactory.createEmptyBorder());
    for (final Object component : components) {
        if (component instanceof Component) {
            initComponentHeight((Component) component);
            jp.add((Component) component);
        } else if (component instanceof Number) {
            jp.add(Box.createHorizontalStrut(((Number) component).intValue()));
        }//w  w  w. j  a  v a2 s. c o  m
    }
    return jp;
}

From source file:Main.java

public static JComponent wrapBorder(Component content, Border border) {
    JPanel wrapper = new JPanel(new BorderLayout());
    wrapper.add(content, BorderLayout.CENTER);
    wrapper.setBorder(border);
    return wrapper;
}