Java tutorial
import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Insets; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; public class BorderExample { public static void main(String[] args) { JPanel panel = new JPanel(new BorderLayout()); JPanel top = new JPanel(); top.setBackground(Color.gray); top.setPreferredSize(new Dimension(250, 150)); panel.add(top); panel.setBorder(new EmptyBorder(new Insets(10, 20, 30, 40))); JFrame f = new JFrame(); f.add(panel); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } }