Creating a JButton without a border


JButtonBorder.java:
import javax.swing.*;
import java.awt.event.*;
 
public class JButtonBorder extends JFrame {
 
   private JButton b1, b2;
   private JPanel p;
 
   public JButtonBorder() {
      super("JButtonBorder");
      p = new JPanel();
      b1 = new JButton("button with border");
      b2 = new JButton("button without border");
	
      b2.setBorderPainted(false);
 
      setContentPane(p);
      p.add(b1);
      p.add(b2);
 	
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent event) {
            dispose();
            System.exit(0);
         }
      });
 
      pack();
      setVisible(true);
   }
 
   public static void main(String args[]) {
      JButtonBorder j = new JButtonBorder();
   }
}