Example usage for javax.swing JButton getBackground

List of usage examples for javax.swing JButton getBackground

Introduction

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

Prototype

@Transient
public Color getBackground() 

Source Link

Document

Gets the background color of this component.

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JButton button = new JButton("Pick to Change Background");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Color initialBackground = button.getBackground();
            Color background = JColorChooser.showDialog(null, "JColorChooser Sample", initialBackground);
            if (background != null) {
                button.setBackground(background);
            }//from  ww w  . j a  v  a2 s  .c  o m
        }
    };
    button.addActionListener(actionListener);
    f.add(button, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:ColorChooserSample.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    final JButton button = new JButton("Pick to Change Background");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Color initialBackground = button.getBackground();
            Color background = JColorChooser.showDialog(null, "JColorChooser Sample", initialBackground);
            if (background != null) {
                button.setBackground(background);
            }//from ww w.j ava2s.  c  om
        }
    };
    button.addActionListener(actionListener);
    content.add(button, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:ColorSamplePopup.java

public static void main(String args[]) {

    JFrame frame = new JFrame("JColorChooser Sample Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JButton button = new JButton("Pick to Change Background");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Color initialBackground = button.getBackground();
            Color background = JColorChooser.showDialog(null, "Change Button Background", initialBackground);
            if (background != null) {
                button.setBackground(background);
            }/*from  ww w  .j  a  v a2 s.c  om*/
        }
    };
    button.addActionListener(actionListener);
    frame.add(button, BorderLayout.CENTER);

    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:CreateColorSamplePopup.java

public static void main(String args[]) {
    JFrame frame = new JFrame("JColorChooser Create Popup Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    final JButton button = new JButton("Pick to Change Background");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Color initialBackground = button.getBackground();

            final JColorChooser colorChooser = new JColorChooser(initialBackground);
            //        colorChooser.setPreviewPanel(new JPanel());
            final JLabel previewLabel = new JLabel("I Love Swing", JLabel.CENTER);
            previewLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48));
            colorChooser.setPreviewPanel(previewLabel);
            // Bug workaround
            colorChooser.updateUI();/* w  w  w .jav a2  s  . co  m*/

            // For okay button selection, change button background to
            // selected color
            ActionListener okActionListener = new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    Color newColor = colorChooser.getColor();
                    if (newColor.equals(button.getForeground())) {
                        System.out.println("Color change rejected");
                    } else {
                        button.setBackground(colorChooser.getColor());
                    }
                }
            };

            // For cancel button selection, change button background to red
            ActionListener cancelActionListener = new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    button.setBackground(Color.red);
                }
            };

            final JDialog dialog = JColorChooser.createDialog(null, "Change Button Background", true,
                    colorChooser, okActionListener, cancelActionListener);

            // Wait until current event dispatching completes before showing
            // dialog
            Runnable showDialog = new Runnable() {
                public void run() {
                    dialog.show();
                }
            };
            SwingUtilities.invokeLater(showDialog);
        }
    };
    button.addActionListener(actionListener);
    contentPane.add(button, BorderLayout.CENTER);

    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:jcine.CineForm.java

void chairPressed(java.awt.event.ActionEvent evt) {
    if (evt.getSource() instanceof JButton) {
        JButton btn = (JButton) evt.getSource();
        if (btn.getBackground() == Color.white) {
            btn.setBackground(null);/*from ww  w  . j  ava  2s  . c o  m*/
        } else {
            btn.setBackground(Color.white);
        }
    }
}

From source file:co.com.soinsoftware.hotelero.view.JFRoom.java

private boolean selectRoom(final JButton button) {
    boolean canSelect = false;
    if (button.getBackground().equals(Color.WHITE)) {
        this.setBackgroundColor(button, Color.GREEN);
        canSelect = true;/*from  w  w w . j a  v a  2s . c  o m*/
    }
    return canSelect;
}

From source file:com.alvermont.terraj.planet.ui.MainFrame.java

/**
 * Bring up a colour selector for the specified colour and set the
 * corresponding colour parameter if the user picks a new one
 *
 * @param source The button that was pressed to produce this action
 * @param label The string to be displayed by the colour dialog
 * @param index The index of the colour parameter to be set
 * @return The new colour that was chosen or <code>null</code> if the
 * user cancelled.//from w w  w  . j a v a  2 s  .c  o m
 */
protected Color pickColour(JButton source, String label, int index) {
    final Color newColour = JColorChooser.showDialog(this, label, source.getBackground());

    if (newColour != null) {
        /// then a new colour was chosen
        source.setBackground(newColour);

        final int[][] colours = params.getProjectionParameters().getColors();

        colours[index][0] = newColour.getRed();
        colours[index][1] = newColour.getGreen();
        colours[index][2] = newColour.getBlue();
    }

    return newColour;
}