Set your JPanel's layout manager to FlowLayout() or BorderLayout() and set its margins using setBorder(BorderFactory.createEmptyBorder(top, left, bottom, right)).