Example usage for javax.swing JColorChooser getSelectionModel

List of usage examples for javax.swing JColorChooser getSelectionModel

Introduction

In this page you can find the example usage for javax.swing JColorChooser getSelectionModel.

Prototype

public ColorSelectionModel getSelectionModel() 

Source Link

Document

Returns the data model that handles color selections.

Usage

From source file:ListeningJColorChooserSample.java

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

    final JLabel label = new JLabel("www.java2s.com", JLabel.CENTER);
    label.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48));

    frame.add(label, BorderLayout.SOUTH);

    final JColorChooser colorChooser = new JColorChooser(label.getBackground());

    ColorSelectionModel model = colorChooser.getSelectionModel();
    ChangeListener changeListener = new ChangeListener() {
        public void stateChanged(ChangeEvent changeEvent) {
            Color newForegroundColor = colorChooser.getColor();
            label.setForeground(newForegroundColor);
        }/*ww  w  . j  ava2  s. c  o  m*/
    };
    model.addChangeListener(changeListener);

    frame.add(colorChooser, BorderLayout.CENTER);

    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) {
    JColorChooser chooser = new JColorChooser();
    final MyPreviewPanel pre = new MyPreviewPanel(chooser);
    chooser.setPreviewPanel(pre);//from  w  w w .  ja v  a2 s  .com

    ColorSelectionModel model = chooser.getSelectionModel();
    model.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent evt) {
            ColorSelectionModel model = (ColorSelectionModel) evt.getSource();
            pre.curColor = model.getSelectedColor();
        }
    });

}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("JColorChooser Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JLabel label = new JLabel("www.java2s.com", JLabel.CENTER);
    label.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48));
    frame.add(label, BorderLayout.SOUTH);

    final JColorChooser colorChooser = new JColorChooser(label.getBackground());
    colorChooser.setBorder(BorderFactory.createTitledBorder("Pick Color for java2s.com"));

    ColorSelectionModel model = colorChooser.getSelectionModel();
    ChangeListener changeListener = new ChangeListener() {
        public void stateChanged(ChangeEvent changeEvent) {
            Color newForegroundColor = colorChooser.getColor();
            label.setForeground(newForegroundColor);
        }//w  w  w . j av  a  2  s .c  o m
    };
    model.addChangeListener(changeListener);
    frame.add(colorChooser, BorderLayout.CENTER);

    frame.pack();
    frame.setVisible(true);
}