Java Utililty Methods Swing TitledBorder

List of utility methods to do Swing TitledBorder

Description

The list of methods to do Swing TitledBorder are organized into topic(s).

Method

BorderCreateTitledBorderwMargin(String title, int topMargin, int leftMargin, int bottomMargin, int rightMargin)
Creates a Titled border having title that is on top and specified margins around it.
Border bdrMargin = BorderFactory.createEmptyBorder(topMargin, leftMargin, bottomMargin, rightMargin);
return BorderFactory.createCompoundBorder(bdrMargin, BorderFactory.createTitledBorder(title));
TitledBordercreateTitledPanelBorder(String title)
create Titled Panel Border
TitledBorder border = BorderFactory.createTitledBorder(title);
Font font = border.getTitleFont();
if (font == null) {
    font = UIManager.getFont("TitledBorder.font"); 
border.setTitleFont(new Font(font.getName(), Font.ITALIC, font.getSize()));
return border;
TitledBorderformatTitle(TitledBorder titledBorder)
Formats the title of a given TitledBorder

Workaround for Java Bug ID: 7022041

Font titleBorderFont = UIManager.getDefaults().getFont("TitledBorder.font");
if (titleBorderFont != null) {
    titledBorder.setTitleFont(new Font(titleBorderFont.getName(), Font.BOLD, titleBorderFont.getSize()));
return titledBorder;
BordergetBorder(String title)
get Border
Border loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
Border b1 = BorderFactory.createEmptyBorder(5, 5, 5, 5);
Border b2 = BorderFactory.createTitledBorder(loweredetched, title);
return BorderFactory.createCompoundBorder(b1, b2);
InsetsgetBorderInsetsForNoComponent(Border border)
get Border Insets For No Component
if (border instanceof TitledBorder) {
    return border.getBorderInsets(new Component() {
    });
return border.getBorderInsets(null);
CompoundBordergetCompoundBorder(String text)
get Compound Border
return BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(text),
        BorderFactory.createEmptyBorder(5, 5, 5, 5));
intgetTitledBorderHeight(Border border)
get Titled Border Height
if (border instanceof TitledBorder) {
    int fontSize = ((TitledBorder) border).getTitleFont() != null
            ? ((TitledBorder) border).getTitleFont().getSize()
            : 11;
    return fontSize + 4; 
return 0;
BordergetTitleLabelBorder()
Returns a border used in the TitlePanels.
Border b1 = BorderFactory.createMatteBorder(1, 1, 0, 0, Color.WHITE);
Border b2 = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.GRAY);
Border b3 = new EmptyBorder(3, 5, 3, 5);
Border b = BorderFactory.createCompoundBorder(BorderFactory.createCompoundBorder(b2, b1), b3);
return b;
JPanelmakeBorderedPanel(String borderTitle)
make Bordered Panel
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(borderTitle));
return panel;
BordermakeTitledBorder(String title)
make Titled Border
return BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title);