JButton with setRolloverIcon

setRolloverIcon()

you can define different icons that are displayed for the button when it is disabled, pressed, or selected. Another icon can be used as a rollover icon, which is displayed when the mouse is positioned over a button.

Program

gfg

 

 

 

Program Source

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.FlowLayout;

class Frame extends JFrame {
 
    Frame()
    {
        setTitle("setRolloverIcon");
        setLayout(new FlowLayout());
        setButton();
        setSize(700, 200);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
 
    private void setButton()
    {
        JButton jb1 = new JButton("JButton01",new ImageIcon("icon1.png"));
        jb1.setRolloverIcon(new ImageIcon("icon2.png"));
        add(jb1);
    }
}

public class Javaapp {

    public static void main(String[] args) {
     
        Frame frame = new Frame();
    }
}

Leave a Comment