JButton btn = new JButton("Click me!"); btn.setBorder(BorderFactory.createLineBorder(Color.BLACK));
JButton btn = new JButton("Click me!"); btn.setBorder(BorderFactory.createTitledBorder("My Button"));
JButton btn = new JButton("Click me!"); btn.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
JButton btn = new JButton("Click me!"); Border lineBorder = BorderFactory.createLineBorder(Color.BLACK); Border emptyBorder = BorderFactory.createEmptyBorder(5, 10, 5, 10); btn.setBorder(BorderFactory.createCompoundBorder(lineBorder, emptyBorder));This code sets a compound border with a black line border on the outside and an empty border with 5 pixels on the top and bottom and 10 pixels on the left and right sides on the inside of the JButton. Package library: java.swing.BorderFactory