JColorChooser Component in Java
Submitted by donbermoy on Thursday, May 29, 2014 - 13:19.
Today, i will teach you how to create a program that has the JColorChooser component in Java. We have ColorDialog in VB.NET and C# and this is equivalent to the JColorChooser in Java.
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of colorChooser.java.
2. Import java.awt.* and javax.swing.* packages because we will going to have the JColorChooser component in swing and also the JPanel as the container of this.
3. Creates an instance of JColorChooser and set Color.RED as the default selected color and named it as jcc. This will be below in your public class colorChooser extends JFrame .
4. Create a constructor that is the same with the filename and create a panel out of there to hold the JColorChooser and its border.
Set window characteristics of the program. This will also add the panel and the jcolorchooser with its title and closing event.
5. In your Main, create a JFrame component that will hold the panel and the JColorChooser component and all other components. This will set the visibility to True.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
- import javax.swing.*;
- import java.awt.*;
- this.setContentPane(content);
- this.setTitle("JColorChooser Component");
- this.pack();
Press F5 and run the program.
Output:
Full source code:
- import javax.swing.*;
- import java.awt.*;
- public colorChooser() {
- this.setContentPane(content);
- this.setTitle("JColorChooser Component");
- this.pack();
- }
- chooser.setVisible(true);
- }
- }
Add new comment
- 148 views