Here you can find the source of withTitledBorder(String title, JComponent c)
public static JPanel withTitledBorder(String title, JComponent c)
//package com.java2s; /***// www . j a v a 2 s . c om * Copyright (C) 2010 Johan Henriksson * This code is under the Endrov / BSD license. See www.endrov.net * for the full text and how to cite. */ import java.awt.GridLayout; import javax.swing.*; public class Main { /** * Place content within a titled border */ public static JPanel withTitledBorder(String title, JComponent c) { JPanel p = new JPanel(new GridLayout(1, 1)); p.setBorder(BorderFactory.createTitledBorder(title)); p.add(c); return p; } }