Example usage for javax.swing BorderFactory createTitledBorder

List of usage examples for javax.swing BorderFactory createTitledBorder

Introduction

In this page you can find the example usage for javax.swing BorderFactory createTitledBorder.

Prototype

public static TitledBorder createTitledBorder(Border border) 

Source Link

Document

Creates a new titled border with an empty title, the specified border object, the default text position (determined by the current look and feel), the default justification (leading), and the default font and text color (determined by the current look and feel).

Usage

From source file:RadioButtonUtils.java

public static Container createRadioButtonGrouping(String elements[], String title) {
    JPanel panel = new JPanel(new GridLayout(0, 1));

    if (title != null) {
        Border border = BorderFactory.createTitledBorder(title);
        panel.setBorder(border);/*w  ww  . j av  a 2  s  .c  o  m*/
    }

    ButtonGroup group = new ButtonGroup();
    JRadioButton aRadioButton;

    for (int i = 0, n = elements.length; i < n; i++) {
        aRadioButton = new JRadioButton(elements[i]);
        panel.add(aRadioButton);
        group.add(aRadioButton);
    }
    return panel;
}

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
 *//*from   w  w w  .  ja  va2 s .com*/
public static void addTitledBorder(JComponent c, String title) {
    TitledBorder titledBorder;
    titledBorder = BorderFactory.createTitledBorder(title);
    c.setBorder(titledBorder);
}

From source file:YAxisAlignXButtonMixed.java

private static Container makeIt(String title) {
    JPanel container = new JPanel();
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);//from  www .  j  a  v  a2  s  . c o m

    AButton button = new AButton("0.0", 0.0f);
    container.add(button);
    button = new AButton(".25", .25f);
    container.add(button);
    button = new AButton(".50", .50f);
    container.add(button);
    button = new AButton(".75", .75f);
    container.add(button);
    button = new AButton("1.0", 1.0f);
    container.add(button);
    return container;
}

From source file:Main.java

/**
 * @param title/* w  ww  . j  av a 2s .  c  o  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:XAxisDiffAlign.java

private static Container makeIt(String title, boolean more) {
    JPanel container = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            int width = getWidth();
            int height = getHeight() - insets.top - insets.bottom;
            int halfHeight = height / 2 + insets.top;
            g.drawLine(0, halfHeight, width, halfHeight);
        }/*w  ww . java 2 s  . co  m*/
    };
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS);
    container.setLayout(layout);

    JButton button;
    button = new JButton("0.0");
    button.setOpaque(false);
    button.setAlignmentY(Component.TOP_ALIGNMENT);
    container.add(button);
    if (more) {
        button = new JButton(".25");
        button.setOpaque(false);
        button.setAlignmentY(0.25f);
        container.add(button);
        button = new JButton(".5");
        button.setOpaque(false);
        button.setAlignmentY(Component.CENTER_ALIGNMENT);
        container.add(button);
        button = new JButton(".75");
        button.setOpaque(false);
        button.setAlignmentY(0.75f);
        container.add(button);
    }
    button = new JButton("1.0");
    button.setOpaque(false);
    button.setAlignmentY(Component.BOTTOM_ALIGNMENT);
    container.add(button);

    return container;
}

From source file:Main.java

public static CompoundBorder getCompoundBorder(String text) {
    return BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(text),
            BorderFactory.createEmptyBorder(5, 5, 5, 5));
}

From source file:YAxisDiffAlign.java

private static Container makeIt(String title, boolean more) {
    JPanel container = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            int width = getWidth() - insets.left - insets.right;
            int halfWidth = width / 2 + insets.left;
            int height = getHeight();
            int halfHeight = height / 2 + insets.top;
            g.drawLine(halfWidth, 0, halfWidth, height);
        }/*from  w  w  w .j a  v a2 s .co  m*/
    };
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);

    JButton button;
    button = new JButton("0.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.LEFT_ALIGNMENT);
    container.add(button);
    if (more) {
        button = new JButton(".25");
        button.setOpaque(false);
        button.setAlignmentX(0.25f);
        container.add(button);
        button = new JButton(".5");
        button.setOpaque(false);
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        container.add(button);
        button = new JButton(".75");
        button.setOpaque(false);
        button.setAlignmentX(0.75f);
        container.add(button);
    }
    button = new JButton("1.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.RIGHT_ALIGNMENT);
    container.add(button);

    return container;
}

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  .ja  v  a 2  s  . c  om
    return p;
}

From source file:Main.java

public Main() {
    JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));

    simplePanel.setBorder(BorderFactory.createTitledBorder("Title Border"));
    simplePanel.add(new JLabel("Examples"), JLabel.CENTER);

    add(simplePanel);/*from  w ww  .  ja  va2s .  c  o m*/
}

From source file:Main.java

public Main() {
    JPanel borderLayoutPanel = new JPanel(new BorderLayout());
    borderLayoutPanel.setBorder(BorderFactory.createTitledBorder("BorderLayout Panel"));
    borderLayoutPanel.add(createGridPanel(), BorderLayout.CENTER);

    JPanel flowLayoutPanel = new JPanel(new FlowLayout());
    flowLayoutPanel.setBorder(BorderFactory.createTitledBorder("FlowLayout Panel"));
    flowLayoutPanel.add(createGridPanel());

    setBorder(BorderFactory.createEmptyBorder(GAP, GAP, GAP, GAP));
    setLayout(new GridLayout(1, 0, GAP, 0));
    add(borderLayoutPanel);// w ww.  j av  a  2 s . co  m
    add(flowLayoutPanel);
}