Display Color chooser dialog : JColorChooser « Swing « Java Tutorial

Java Tutorial
1. Language
2. Data Type
3. Operators
4. Statement Control
5. Class Definition
6. Development
7. Reflection
8. Regular Expressions
9. Collections
10. Thread
11. File
12. Generics
13. I18N
14. Swing
15. Swing Event
16. 2D Graphics
17. SWT
18. SWT 2D Graphics
19. Network
20. Database
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web Services SOA
27. EJB3
28. Spring
29. PDF
30. Email
31. J2ME
32. J2EE Application
33. XML
34. Design Pattern
35. Log
36. Security
37. Apache Common
38. Ant
39. JUnit
Java
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » Swing » JColorChooser 
14. 76. 1. Display Color chooser dialog
Display Color chooser dialog
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;

public class ColorSample {
  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);
        }
      }
    };
    button.addActionListener(actionListener);
    f.add(button, BorderLayout.CENTER);
    f.setSize(300200);
    f.setVisible(true);
  }
}
14. 76. JColorChooser
14. 76. 1. Display Color chooser dialogDisplay Color chooser dialog
14. 76. 2. Use a Color Chooser
14. 76. 3. Creating a JColorChooser Dialog
14. 76. 4. Getting and Setting the Selected Color in a JColorChooser Dialog
14. 76. 5. Preview pane simply displays the currently selected color.
14. 76. 6. Listening to Color Selection ChangesListening to Color Selection Changes
14. 76. 7. Creating and Showing a JColorChooser Pop-Up WindowCreating and Showing a JColorChooser Pop-Up Window
14. 76. 8. Customizing Action Listeners on JColorChooser ButtonsCustomizing Action Listeners on JColorChooser Buttons
14. 76. 9. Linking JColorChooser with component's colorLinking JColorChooser with component's color
14. 76. 10. Dragging-and-Dropping Colors Across JColorChooser ComponentsDragging-and-Dropping Colors Across JColorChooser Components
14. 76. 11. JColorChooser with custom preview panel
14. 76. 12. Changing the Color Chooser PanelsChanging the Color Chooser Panels
14. 76. 13. Setting the Order of the Color Chooser Panel Tabs in a JColorChooser Dialog
14. 76. 14. Retrieving the Color Chooser Panels in a JColorChooser Dialog
14. 76. 15. Removing a Color Chooser Panel from a JColorChooser Dialog
14. 76. 16. Removing the Preview Panel from a JColorChooser Dialog
14. 76. 17. Customizing the Preview Panel of a JColorChooser Dialog
14. 76. 18. Listening for OK and Cancel Events in a JColorChooser Dialog
14. 76. 19. Adding a Custom Color Chooser Panel to a JColorChooser Dialog
14. 76. 20. Customizing a JColorChooser Look and Feel
14. 76. 21. Choose foreground or background color
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.