Java Swing TitledBorder createTitledBorder(String title)

Here you can find the source of createTitledBorder(String title)

Description

This method creates and returns a border.

License

Apache License

Parameter

Parameter Description
title The text displayed on the border.

Return

A border.

Declaration

public static TitledBorder createTitledBorder(String title) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import static java.awt.Color.BLACK;
import static java.awt.Color.GRAY;
import static java.awt.Font.BOLD;
import static javax.swing.BorderFactory.createEtchedBorder;
import javax.swing.border.MatteBorder;
import javax.swing.border.TitledBorder;

public class Main {
    /**/*from  w ww  .  java2s  .com*/
     * This method creates and returns a border.
     *
     * @param title The text displayed on the border.
     *
     * @return A border.
     */
    public static TitledBorder createTitledBorder(String title) {
        return createTitledBorder(title, true);
    }

    /**
     * This method creates and returns a border.
     *
     * @param title The text displayed on the border.
     * @param showBorder Whether or not to show the outlining of the border.
     *
     * @return A border.
     */
    public static TitledBorder createTitledBorder(String title, boolean showBorder) {
        TitledBorder border = new TitledBorder(title);

        // Build border.
        if (showBorder == true) {
            border.setBorder(createEtchedBorder());
        } else {
            border.setBorder(new MatteBorder(1, 0, 0, 0, GRAY));
        }

        border.setTitleColor(BLACK);
        if (border.getTitleFont() != null) {
            border.setTitleFont(border.getTitleFont().deriveFont(BOLD, 11.0f));
        }
        return border;
    }
}

Related

  1. createTitleBorder(final String title)
  2. createTitledBorder(final String title)
  3. createTitledBorder(String label)
  4. createTitledBorder(String name)
  5. createTitledBorder(String title)
  6. CreateTitledBorderwMargin(String title, int topMargin, int leftMargin, int bottomMargin, int rightMargin)
  7. createTitledPanelBorder(String title)
  8. formatTitle(TitledBorder titledBorder)
  9. getBorder(String title)