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, String title) 

Source Link

Document

Adds a title to an existing border, with default positioning (determined by the current look and feel), default justification (leading) and the default font and text color (determined by the current look and feel).

Usage

From source file:Main.java

public static void main(String[] argv) {
    LineBorder border = new LineBorder(Color.red);
    TitledBorder titledBorder = BorderFactory.createTitledBorder(border, "Title");
}

From source file:Main.java

public static void main(String[] argv) {
    LineBorder border = new LineBorder(Color.red);
    TitledBorder titledBorder = BorderFactory.createTitledBorder(border, "Title");

    // Or: DEFAULT_JUSTIFICATION, LEFT, RIGHT
    titledBorder.setTitleJustification(TitledBorder.CENTER);
}

From source file:Main.java

public static void main(String[] argv) {
    LineBorder border = new LineBorder(Color.red);
    TitledBorder titledBorder = BorderFactory.createTitledBorder(border, "Title");

    // Or: DEFAULT_POSITION, ABOVE_TOP, TOP, ABOVE_BOTTOM, BOTTOM, BELOW_BOTTOM
    titledBorder.setTitlePosition(TitledBorder.BELOW_TOP);
}

From source file:Borders.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Borders");

    int center = SwingConstants.CENTER;
    JLabel labelOne = new JLabel("raised BevelBorder", center);
    labelOne.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    JLabel labelTwo = new JLabel("EtchedBorder", center);
    labelTwo.setBorder(BorderFactory.createEtchedBorder());
    JLabel labelThree = new JLabel("MatteBorder", center);
    labelThree.setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.pink));
    JLabel labelFour = new JLabel("TitledBorder", center);
    Border etch = BorderFactory.createEtchedBorder();
    labelFour.setBorder(BorderFactory.createTitledBorder(etch, "Title"));
    JLabel labelFive = new JLabel("TitledBorder", center);
    Border low = BorderFactory.createLoweredBevelBorder();
    labelFive//from  w w w . java2  s. c  o m
            .setBorder(BorderFactory.createTitledBorder(low, "Title", TitledBorder.RIGHT, TitledBorder.BOTTOM));
    JLabel labelSix = new JLabel("CompoundBorder", center);
    Border one = BorderFactory.createEtchedBorder();
    Border two = BorderFactory.createMatteBorder(4, 4, 4, 4, Color.blue);
    labelSix.setBorder(BorderFactory.createCompoundBorder(one, two));

    frame.setLayout(new GridLayout(3, 2));
    frame.add(labelOne);
    frame.add(labelTwo);
    frame.add(labelThree);
    frame.add(labelFour);
    frame.add(labelFive);
    frame.add(labelSix);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static Border getTitledBorder(String title) {
    return BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(etchedBorder, title),
            empty10Border);/*ww  w . ja  va2  s .  co m*/
}

From source file:JListBackground.java

public static void addComponentsToPane(Container pane) {
    String[] bruteForceCode = { "int count = 0", "int m = mPattern.length();", "int n = mSource .length();",
            "outer:", " ++count;", " }", " return count;", "}" };
    JList list = new JList(bruteForceCode);
    Border etch = BorderFactory.createEtchedBorder();
    list.setBorder(BorderFactory.createTitledBorder(etch, "Brute Force Code"));
    JPanel listPanel = new JPanel();
    listPanel.add(list);//from  w  w  w . j av  a  2s.  c om
    listPanel.setBackground(lightBlue);
    list.setBackground(lightBlue);

    pane.add(listPanel, BorderLayout.CENTER);
    pane.setBackground(lightBlue);
}

From source file:Main.java

public static <T extends JComponent> JScrollPane wrap(final T component, final String title) {

    final JScrollPane scrollPane = new JScrollPane(component);
    scrollPane.setBorder(BorderFactory.createTitledBorder(scrollPane.getBorder(), title));
    return scrollPane;
}

From source file:Main.java

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

    simplePanel.setBorder(BorderFactory.createTitledBorder(
            BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Title Lowered Etched Border"));
    simplePanel.add(new JLabel("Examples"), JLabel.CENTER);

    add(simplePanel);/*w  w  w  .j a  v  a  2 s  .c  o  m*/
}

From source file:Main.java

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

    simplePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLUE),
            "Title Line Border with color"));
    simplePanel.add(new JLabel("Examples"), JLabel.CENTER);

    add(simplePanel);//from   www.  ja  v  a2s .c om
}

From source file:Main.java

public Main() {
    getContentPane().setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    JPanel panel1 = new JPanel();
    Border eBorder = BorderFactory.createEtchedBorder();
    panel1.setBorder(BorderFactory.createTitledBorder(eBorder, "70pct"));
    gbc.gridx = gbc.gridy = 0;// ww w  .j a v  a 2 s . co m
    gbc.gridwidth = gbc.gridheight = 1;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.weightx = gbc.weighty = 70;
    getContentPane().add(panel1, gbc);
    JPanel panel2 = new JPanel();
    panel2.setBorder(BorderFactory.createTitledBorder(eBorder, "30pct"));
    gbc.gridy = 1;
    gbc.weightx = 30;
    gbc.weighty = 30;
    gbc.insets = new Insets(2, 2, 2, 2);
    getContentPane().add(panel2, gbc);
    pack();
}