Source Code : Create a JButton that does not show focus

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Create a JButton that does not show focus

Create a JButton that does not show focus
  
//Create a JButton that does not show focus, does not paint a border, and
//displays different icons when rolled-over and pressed.

import java.awt.Container;
import java.awt.FlowLayout;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;

public class FancyButton extends JButton {
  public FancyButton(Icon icon, Icon pressed, Icon rollover) {
    super(icon);
    setFocusPainted(false);
    setRolloverEnabled(true);
    setRolloverIcon(rollover);
    setPressedIcon(pressed);
    setBorderPainted(false);
    setContentAreaFilled(false);
  }

  public static void main(String[] args) {

    FancyButton b1 = new FancyButton(new ImageIcon("1.gif"),new ImageIcon("2.gif"), new ImageIcon("3.gif"));
    FancyButton b2 = new FancyButton(new ImageIcon("4.gif"),new ImageIcon("1.gif"), new ImageIcon("2.gif"));
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container c = f.getContentPane();
    c.setLayout(new FlowLayout());
    c.add(b1);
    c.add(b2);
    f.pack();
    f.setVisible(true);
  }
}

           
         
    
  

Thank with us