Here you can find the source of addMarginBorder(JPanel panel, String title, int top, int left, int bottom, int right)
public static void addMarginBorder(JPanel panel, String title, int top, int left, int bottom, int right)
//package com.java2s; import javax.swing.BorderFactory; import javax.swing.JPanel; import javax.swing.border.Border; import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; public class Main { public static void addMarginBorder(JPanel panel, String title, int top, int left, int bottom, int right) { Border border = BorderFactory.createTitledBorder(title); Border marginBorder = new EmptyBorder(top, left, bottom, right); panel.setBorder(new CompoundBorder(marginBorder, border)); }//from ww w.j a v a2 s . c om }