How to Remove Border Around JButton in Java
In this tutorial, we are going to see how to remove border around JButton in Java by using the method setBorder().

[st_adsense]
Java Program to Remove Border Around JButton:
import javax.swing.*; import java.awt.*; import javax.swing.border.Border; public class JButtonExample { public static void main(String[] args) { //create a frame JFrame frame = new JFrame("JButton Example"); //create button JButton btn = new JButton("Click here"); //set button position btn.setBounds(70,80,100,30); //change the background color of JButton btn.setBackground(Color.RED); //create an empty border Border emptyBorder = BorderFactory.createEmptyBorder(); //set border to empty btn.setBorder(emptyBorder); //add button to frame frame.add(btn); frame.setSize(250,250); frame.setLayout(null); frame.setVisible(true); } }
Output:
