Example usage for javax.swing JButton setRolloverIcon

List of usage examples for javax.swing JButton setRolloverIcon

Introduction

In this page you can find the example usage for javax.swing JButton setRolloverIcon.

Prototype

@BeanProperty(visualUpdate = true, description = "The rollover icon for the button.")
public void setRolloverIcon(Icon rolloverIcon) 

Source Link

Document

Sets the rollover icon for the button.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JButton button = new JButton();
    // Add rollover icon
    Icon rolloverIcon = new ImageIcon("r.gif");
    button.setRolloverIcon(rolloverIcon);

    // Add pressed icon
    Icon pressedIcon = new ImageIcon("p.gif");
    button.setPressedIcon(pressedIcon);// www  . j  a v  a  2 s.c o m

    // To remove rollover icon, set to null
    button.setRolloverIcon(null);

    // To remove pressed icon, set to null
    button.setPressedIcon(null);

}

From source file:Main.java

public static void main(final String args[]) {
    JButton button = new JButton();
    // Add rollover icon
    Icon rolloverIcon = new ImageIcon("r.gif");
    button.setRolloverIcon(rolloverIcon);

    // Add pressed icon
    Icon pressedIcon = new ImageIcon("p.gif");
    button.setPressedIcon(pressedIcon);/* www .j av a 2s .  com*/

    // To remove rollover icon, set to null
    button.setRolloverIcon(null);

    // To remove pressed icon, set to null
    button.setPressedIcon(null);

    JOptionPane.showMessageDialog(null, button);
}

From source file:Main.java

public static void main(final String args[]) {
    JButton button = new JButton("Test");

    button.setHorizontalTextPosition(SwingConstants.LEFT);
    button.setIcon(new ImageIcon("r.gif"));
    button.setRolloverIcon(new ImageIcon("b.gif"));
    button.setRolloverEnabled(true);//from   w  ww. j a v  a2s  .c  om

    JOptionPane.showMessageDialog(null, button);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    Icon normalIcon = new TriangleIcon(Color.red, TriangleIcon.State.NORMAL);
    Icon pressedIcon = new TriangleIcon(Color.red, TriangleIcon.State.PRESSED);
    Icon rolloverIcon = new TriangleIcon(Color.red, TriangleIcon.State.ROLLOVER);
    JButton b = new JButton("Button", normalIcon);
    b.setPressedIcon(pressedIcon);//from w  w  w. java  2 s  .  c  o m
    b.setRolloverIcon(rolloverIcon);
    b.setRolloverEnabled(true);
    contentPane.add(b, BorderLayout.NORTH);
    frame.setSize(300, 100);
    frame.show();
}

From source file:Main.java

public static void main(String args[]) {
    ImageIcon iconA = new ImageIcon("IconA.gif");
    ImageIcon iconDiable = new ImageIcon("disable.gif");
    ImageIcon iconOver = new ImageIcon("over.gif");
    ImageIcon iconPressed = new ImageIcon("IconAPressed.gif");

    final JButton jbtnA = new JButton("Alpha", iconA);

    JFrame jfrm = new JFrame();
    jfrm.setLayout(new FlowLayout());
    jfrm.setSize(300, 300);//from  w  w  w. j a v a  2s.  com

    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jbtnA.setRolloverIcon(iconOver);

    jbtnA.setPressedIcon(iconPressed);
    jbtnA.setDisabledIcon(iconDiable);

    jfrm.getRootPane().setDefaultButton(jbtnA);

    jbtnA.setMnemonic(KeyEvent.VK_A);

    jbtnA.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            System.out.println("Alpha pressed. Beta is enabled.");
            jbtnA.setEnabled(!jbtnA.isEnabled());
        }
    });
    jfrm.add(jbtnA);
    jfrm.setVisible(true);
}

From source file:BooksDemo.java

public static JButton createButton(String text, String icon, boolean flat) {
    ImageIcon iconNormal = readImageIcon(icon + ".png");
    ImageIcon iconHighlight = readImageIcon(icon + "_highlight.png");
    ImageIcon iconPressed = readImageIcon(icon + "_pressed.png");

    JButton button = new JButton(text, iconNormal);
    button.setFocusPainted(!flat);//from  w  w  w .  j  a  v  a2 s .  c o  m
    button.setBorderPainted(!flat);
    button.setContentAreaFilled(!flat);
    if (iconHighlight != null) {
        button.setRolloverEnabled(true);
        button.setRolloverIcon(iconHighlight);
    }
    if (iconPressed != null)
        button.setPressedIcon(iconPressed);
    return button;
}

From source file:Main.java

@Override
protected JButton createArrowButton() {
    JButton btn = new JButton();
    btn.setIcon(infoIcon);/* w w  w.j  av  a 2  s . c  o m*/
    btn.setRolloverIcon(warnIcon);
    return btn;
}

From source file:ButtonwithImageIcon.java

public ButtonPanel() {

    JButton btn = new JButton("Push Me", new BoxIcon(Color.blue, 2));
    btn.setRolloverIcon(new BoxIcon(Color.cyan, 3));
    btn.setPressedIcon(new BoxIcon(Color.yellow, 4));

    btn.setHorizontalTextPosition(JButton.LEFT);
    btn.setBorder(BorderFactory.createEtchedBorder());
    btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Button was pressed.");
        }/*  ww  w .j  a v  a  2  s .c  o m*/
    });
    add(btn);
}

From source file:SampleButton.java

public SampleButton() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel(new BorderLayout());
    p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    JButton b = new JButton("Test");
    b.setHorizontalTextPosition(SwingConstants.LEFT);
    b.setIcon(new ImageIcon("r.gif"));
    b.setRolloverIcon(new ImageIcon("b.gif"));
    b.setRolloverEnabled(true);/*from  w w w . j  av  a  2  s.c o m*/

    b.setMnemonic('t');
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Button pressed");
        }
    });
    p.add(b);
    getContentPane().add(p);
    pack();
}

From source file:edu.ku.brc.af.ui.forms.formatters.UIFormatterEditorDlg.java

/**
 * @param type/* w ww  .java  2 s  . c  o  m*/
 * @return
 */
private JButton createClose(final int type) {
    JButton btn = UIHelper.createIconBtn("Close", "", new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            checkForChanges();
            cardLayout.show(cardPanel, "none");
            resetUI();
        }
    });
    btn.setRolloverEnabled(true);
    btn.setRolloverIcon(IconManager.getIcon("CloseHover"));
    btn.setEnabled(true);
    return btn;
}