Java BorderFactory create compound border
import java.awt.Color; import java.awt.FlowLayout; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; class Demo extends JPanel { public Demo() { setLayout(new FlowLayout()); // Create the UI for displaying result. JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEADING); // == LEFT resultLabel.setForeground(Color.black); resultLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black), BorderFactory.createEmptyBorder(5, 5, 5, 5))); add(resultLabel);//from w w w . j a va 2 s . c o m } } public class Main { public static void main(String[] args) { Demo panel = new Demo(); JFrame application = new JFrame(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); application.add(panel); application.setSize(250, 250); application.setVisible(true); } }