Java examples for Swing:Border
add Title Border to JComponent
//package com.java2s; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.border.Border; public class Main { public static void addTitleBorder(JComponent comp, String title) { comp.setBorder(BorderFactory.createTitledBorder(comp.getBorder(), title));/*w w w . jav a 2s . c o m*/ } public static void addTitleBorder(JComponent comp, String title, int margin) { addTitleBorder(comp, title, margin, true); } public static void addTitleBorder(JComponent comp, String title, int margin, boolean origBorderInside) { comp.setBorder(BorderFactory.createTitledBorder( createCompoundBorder(createEmptyBorder(margin), comp.getBorder(), origBorderInside), title)); } public static Border createCompoundBorder(Border border1, Border border2, boolean border2Inside) { if (border2Inside) { return BorderFactory.createCompoundBorder(border1, border2); } else { return BorderFactory.createCompoundBorder(border2, border1); } } public static Border createEmptyBorder(int margin) { return BorderFactory.createEmptyBorder(margin, margin, margin, margin); } }