How to Remove Border Around Text in JButton
In this tutorial, we are going to see how to remove the border around text in the JButton by using the method setFocusPainted().
[st_adsense]
Java Program to Remove Border Around Text in JButton:
import javax.swing.*; import java.awt.*; 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 button background color btn.setBackground(Color.RED); //change button text color btn.setForeground(Color.WHITE); //change JButton border (size = 5) btn.setBorder(BorderFactory.createLineBorder(Color.ORANGE,5)); //remove border around text btn.setFocusPainted(false); //add button to frame frame.add(btn); frame.setSize(250,250); frame.setLayout(null); frame.setVisible(true); } }
Output: