boobies69
Site Builder
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
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.
Press F5 and run the program.
Output:
Full source code:
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
Download
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.
- import
javax.swing.*
;
- import
java.awt.*
;
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 .
- JColorChooser
jcc =
new
JColorChooser
(
Color
.RED
)
;
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.
- JPanel
content =
new
JPanel
(
)
;
- content.setLayout
(
new
BorderLayout
(
)
)
;
- content.add
(
jcc, BorderLayout
.CENTER
)
;
Set window characteristics of the program. This will also add the panel and the jcolorchooser with its title and closing event.
- this
.setContentPane
(
content)
;
- this
.setTitle
(
"JColorChooser Component"
)
;
- this
.setDefaultCloseOperation
(
JFrame
.EXIT_ON_CLOSE
)
;
- this
.pack
(
)
;
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.
- public
static
void
main(
String
[
]
args)
{
- JFrame
chooser =
new
colorChooser(
)
;
- chooser.setVisible
(
true
)
;
- }
Press F5 and run the program.
Output:



Full source code:
- import
javax.swing.*
;
- import
java.awt.*
;
- public
class
colorChooser extends
JFrame
{
- JColorChooser
jcc =
new
JColorChooser
(
Color
.RED
)
;
- public
colorChooser(
)
{
- JPanel
content =
new
JPanel
(
)
;
- content.setLayout
(
new
BorderLayout
(
)
)
;
- content.add
(
jcc, BorderLayout
.CENTER
)
;
- this
.setContentPane
(
content)
;
- this
.setTitle
(
"JColorChooser Component"
)
;
- this
.setDefaultCloseOperation
(
JFrame
.EXIT_ON_CLOSE
)
;
- this
.pack
(
)
;
- }
- public
static
void
main(
String
[
]
args)
{
- JFrame
chooser =
new
colorChooser(
)
;
- chooser.setVisible
(
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
Download
You must upgrade your account or reply in the thread to view hidden text.