Example usage for javax.swing JComponent setBorder

List of usage examples for javax.swing JComponent setBorder

Introduction

In this page you can find the example usage for javax.swing JComponent 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:RedBlueBox.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(0, 1));
    JComponent comp = new RedBlueBox();
    comp.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, Color.PINK));
    contentPane.add(comp);//from   w  ww  . j a  v  a2s .  co  m
    comp = new RedBlueBox();
    contentPane.add(comp);
    frame.setSize(300, 200);
    frame.show();
}

From source file:Main.java

public static void addBorderSpaces(JComponent com) {
    com.setBorder(
            BorderFactory.createCompoundBorder(com.getBorder(), BorderFactory.createEmptyBorder(2, 4, 2, 4)));
}

From source file:Main.java

/**
 * DOCUMENT ME!/*  ww w.  j  a v  a  2 s.com*/
 *
 * @param c DOCUMENT ME!
 */
public static void setBorder6(JComponent c) {
    c.setBorder(border6);
}

From source file:Main.java

/** Set the border of the given components.  Intended to reduce clutter in GUI code. */
public static void setBorder(Border b, JComponent... components) {
    for (JComponent c : components) {
        c.setBorder(b);
    }/*w w  w. ja  v a2 s  .c o m*/
}

From source file:Main.java

/**
 * Sets a title for the given component by surrounding it with a CompoundBorder
 * //  w  w w.  j av a2  s.  com
 * @param component the component
 * @param title the title of the component
 */
public static void setTitle(JComponent component, String title) {
    component.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(title),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
}

From source file:Main.java

/** 
 * Adds a basic black line border around the given component.
 * @param c - the component to put the border around
 *//*from w  w  w. j av  a 2  s .  c  o m*/
public static void addLineBorder(JComponent c) {
    Border lineBorder;
    lineBorder = BorderFactory.createLineBorder(Color.black);
    c.setBorder(lineBorder);
}

From source file:Main.java

public static void makeStandOut(java.awt.Component component) {
    assert component != null;
    if (component instanceof javax.swing.JComponent) {
        javax.swing.JComponent jComponent = (javax.swing.JComponent) component;
        jComponent.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.RED, 4));
        jComponent.setOpaque(true);//from w w w.j a v  a2s. c o m
    }
    component.setBackground(java.awt.Color.GREEN);
}

From source file:Main.java

/** 
 * Adds a basic black line border with the specified title around the given component.
 * @param c - the component to put the border around
 * @param title - the title to give the titled border
 *//* ww  w.j  a v  a  2  s. c  om*/
public static void addTitledBorder(JComponent c, String title) {
    TitledBorder titledBorder;
    titledBorder = BorderFactory.createTitledBorder(title);
    c.setBorder(titledBorder);
}

From source file:Main.java

public static void setMargin(final JComponent component, final Insets newMargin) {
    final Border currentBorder = component.getBorder();
    final Border empty = new EmptyBorder(newMargin.top, newMargin.left, newMargin.bottom, newMargin.right);
    if (currentBorder == null || currentBorder instanceof EmptyBorder) {
        component.setBorder(empty);
    } else if (currentBorder instanceof CompoundBorder) {
        final CompoundBorder current = (CompoundBorder) currentBorder;
        final Border insideBorder = current.getInsideBorder();
        component.setBorder(new CompoundBorder(empty, insideBorder));
    } else {//w w w . ja va 2 s . co m
        component.setBorder(new CompoundBorder(empty, currentBorder));
    }
}

From source file:JTop.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//*from  ww w.  ja  va2s .  co m*/
private static void createAndShowGUI(JPanel jtop) {
    // Create and set up the window.
    JFrame frame = new JFrame("JTop");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the content pane.
    JComponent contentPane = (JComponent) frame.getContentPane();
    contentPane.add(jtop, BorderLayout.CENTER);
    contentPane.setOpaque(true); // content panes must be opaque
    contentPane.setBorder(new EmptyBorder(12, 12, 12, 12));
    frame.setContentPane(contentPane);

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