Example usage for javax.swing JButton setPressedIcon

List of usage examples for javax.swing JButton setPressedIcon

Introduction

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

Prototype

@BeanProperty(visualUpdate = true, description = "The pressed icon for the button.")
public void setPressedIcon(Icon pressedIcon) 

Source Link

Document

Sets the pressed icon for the button.

Usage

From source file:Main.java

public static void main(final String args[]) {
    JButton button = new JButton();
    Icon pressedIcon = new ImageIcon("pres-icon.gif");
    button.setPressedIcon(pressedIcon);

    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);
    b.setRolloverIcon(rolloverIcon);// w  w  w .j  a  v a  2  s  . c o m
    b.setRolloverEnabled(true);
    contentPane.add(b, BorderLayout.NORTH);
    frame.setSize(300, 100);
    frame.show();
}

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);

    // To remove rollover icon, set to null
    button.setRolloverIcon(null);// w ww .  jav a  2 s. c  o  m

    // 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);

    // To remove rollover icon, set to null
    button.setRolloverIcon(null);/* w w w  .j a v a2s. c  o m*/

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

    JOptionPane.showMessageDialog(null, button);
}

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 ww  w .j  av  a  2  s  .  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 ww . j  a  va 2 s .c  om
    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: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  a2 s.  c o  m*/
    });
    add(btn);
}

From source file:edu.gmu.cs.sim.util.media.chart.SeriesAttributes.java

void buildManipulators() {
    JButton removeButton = new JButton(I_CLOSE);
    removeButton.setPressedIcon(I_CLOSE_PRESSED);
    removeButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    removeButton.setBorderPainted(false);
    removeButton.setContentAreaFilled(false);
    removeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showOptionDialog(null, "Remove the Series " + getSeriesName() + "?", "Confirm",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    new Object[] { "Remove", "Cancel" }, null) == 0) // remove
            {//www  . j a  v  a 2 s . co  m
                getGenerator().removeSeries(getSeriesIndex());
            }
        }
    });
    removeButton.setToolTipText("Remove this series");

    JButton upButton = new JButton(I_UP);
    upButton.setPressedIcon(I_UP_PRESSED);
    upButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    upButton.setBorderPainted(false);
    upButton.setContentAreaFilled(false);
    upButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getGenerator().moveSeries(getSeriesIndex(), true);
        }
    });
    upButton.setToolTipText("Draw this series higher in the series order");

    JButton downButton = new JButton(I_DOWN);
    downButton.setPressedIcon(I_DOWN_PRESSED);
    downButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    downButton.setBorderPainted(false);
    downButton.setContentAreaFilled(false);
    downButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getGenerator().moveSeries(getSeriesIndex(), false);
        }
    });
    downButton.setToolTipText("Draw this series lower in the series order");

    manipulators.add(removeButton);
    manipulators.add(upButton);
    manipulators.add(downButton);
}

From source file:sim.util.media.chart.SeriesAttributes.java

void buildManipulators() {
    JButton removeButton = new JButton(I_CLOSE);
    removeButton.setPressedIcon(I_CLOSE_PRESSED);
    removeButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    removeButton.setBorderPainted(false);
    removeButton.setContentAreaFilled(false);
    removeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showOptionDialog(null, "Remove the Series " + getSeriesName() + "?", "Confirm",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    new Object[] { "Remove", "Cancel" }, null) == 0) // remove
                getGenerator().removeSeries(getSeriesIndex());
        }//from  w  w w . java2s .c  om
    });
    removeButton.setToolTipText("Remove this series");

    JButton upButton = new JButton(I_UP);
    upButton.setPressedIcon(I_UP_PRESSED);
    upButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    upButton.setBorderPainted(false);
    upButton.setContentAreaFilled(false);
    upButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getGenerator().moveSeries(getSeriesIndex(), true);
        }
    });
    upButton.setToolTipText("Draw this series higher in the series order");

    JButton downButton = new JButton(I_DOWN);
    downButton.setPressedIcon(I_DOWN_PRESSED);
    downButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4));
    downButton.setBorderPainted(false);
    downButton.setContentAreaFilled(false);
    downButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getGenerator().moveSeries(getSeriesIndex(), false);
        }
    });
    downButton.setToolTipText("Draw this series lower in the series order");

    manipulators.add(removeButton);
    manipulators.add(upButton);
    manipulators.add(downButton);
}

From source file:op.allowance.PnlAllowance.java

private CollapsiblePane createCP4(final Resident resident) {
    /***/*from  ww  w . jav  a 2  s .  co  m*/
     *                          _        ____ ____  _  _    ______           _     _            _ __
     *       ___ _ __ ___  __ _| |_ ___ / ___|  _ \| || |  / /  _ \ ___  ___(_) __| | ___ _ __ | |\ \
     *      / __| '__/ _ \/ _` | __/ _ \ |   | |_) | || |_| || |_) / _ \/ __| |/ _` |/ _ \ '_ \| __| |
     *     | (__| | |  __/ (_| | ||  __/ |___|  __/|__   _| ||  _ <  __/\__ \ | (_| |  __/ | | | |_| |
     *      \___|_|  \___|\__,_|\__\___|\____|_|      |_| | ||_| \_\___||___/_|\__,_|\___|_| |_|\__| |
     *                                                     \_\                                    /_/
     */
    final String key = resident.getRID();
    if (!cpMap.containsKey(key)) {
        cpMap.put(key, new CollapsiblePane());
        try {
            cpMap.get(key).setCollapsed(true);
        } catch (PropertyVetoException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }

    }
    final CollapsiblePane cpResident = cpMap.get(key);

    if (!carrySums.containsKey(getKey(resident, SYSCalendar.eoy(new LocalDate())))) {
        carrySums.put(getKey(resident, SYSCalendar.eoy(new LocalDate())),
                AllowanceTools.getSUM(resident, SYSCalendar.eoy(new LocalDate())));
    }

    BigDecimal sumOverall = carrySums.get(getKey(resident, SYSCalendar.eoy(new LocalDate())));

    String title = "<html><table border=\"0\">" + "<tr>" +

            "<td width=\"520\" align=\"left\"><font size=+1>" + resident.toString() + "</font></td>"
            + "<td width=\"200\" align=\"right\"><font size=+1"
            + (sumOverall.compareTo(BigDecimal.ZERO) < 0 ? " color=\"red\" " : "") + ">" + cf.format(sumOverall)
            + "</font></td>" +

            "</tr>" + "</table>" +

            "</html>";

    DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                cpResident.setCollapsed(!cpResident.isCollapsed());
            } catch (PropertyVetoException pve) {
                // BAH!
            }
        }
    });

    if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.ARCHIVE, internalClassID)
            && OPDE.getAppInfo().isAllowedTo(InternalClassACL.PRINT, internalClassID)) {
        /***
         *      ____       _       _   ____           _     _            _
         *     |  _ \ _ __(_)_ __ | |_|  _ \ ___  ___(_) __| | ___ _ __ | |_
         *     | |_) | '__| | '_ \| __| |_) / _ \/ __| |/ _` |/ _ \ '_ \| __|
         *     |  __/| |  | | | | | |_|  _ <  __/\__ \ | (_| |  __/ | | | |_
         *     |_|   |_|  |_|_| |_|\__|_| \_\___||___/_|\__,_|\___|_| |_|\__|
         *
         */
        final JButton btnPrintResident = new JButton(SYSConst.icon22print2);
        btnPrintResident.setPressedIcon(SYSConst.icon22print2Pressed);
        btnPrintResident.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnPrintResident.setContentAreaFilled(false);
        btnPrintResident.setBorder(null);
        btnPrintResident.setToolTipText(SYSTools.xx("admin.residents.cash.btnprintresident.tooltip"));
        btnPrintResident.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                SYSFilesTools.print(
                        AllowanceTools.getAsHTML(AllowanceTools.getAll(resident), BigDecimal.ZERO, resident),
                        true);
            }

        });
        cptitle.getRight().add(btnPrintResident);
    }

    cpResident.setTitleLabelComponent(cptitle.getMain());
    cpResident.setSlidingDirection(SwingConstants.SOUTH);

    /***
     *           _ _      _            _                               _     _            _
     *       ___| (_) ___| | _____  __| |   ___  _ __    _ __ ___  ___(_) __| | ___ _ __ | |_
     *      / __| | |/ __| |/ / _ \/ _` |  / _ \| '_ \  | '__/ _ \/ __| |/ _` |/ _ \ '_ \| __|
     *     | (__| | | (__|   <  __/ (_| | | (_) | | | | | | |  __/\__ \ | (_| |  __/ | | | |_
     *      \___|_|_|\___|_|\_\___|\__,_|  \___/|_| |_| |_|  \___||___/_|\__,_|\___|_| |_|\__|
     *
     */
    cpResident.addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
        @Override
        public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
            // somebody clicks on the name of the resident. the cash informations
            // are loaded from the database, if necessary.
            cpResident.setContentPane(createContentPanel4(resident));
        }
    });
    cpResident.setBackground(getBG(resident, 7));

    if (!cpResident.isCollapsed()) {
        cpResident.setContentPane(createContentPanel4(resident));
    }

    cpResident.setHorizontalAlignment(SwingConstants.LEADING);
    cpResident.setOpaque(false);

    return cpResident;
}