Showing posts with label color. Show all posts
Showing posts with label color. Show all posts

Set JOptionPane background color

After i make some review over internet and java forum lastly i understand how to change JOptionPane background color.You can try compile and execute simple code below and see it's result.

***************************************************************
COMPLETE SOURCE CODE FOR : SetJOptionPaneBackgroundColor.java
***************************************************************

import javax.swing.JOptionPane;
import javax.swing.UIManager;

import javax.swing.plaf.ColorUIResource;

public class SetJOptionPaneBackgroundColor
{
public static void main(String[]args)
{
UIManager uim=new UIManager();
uim.put("OptionPane.background",new ColorUIResource(255,0,0));
uim.put("Panel.background",new ColorUIResource(255,0,0));

JOptionPane.showMessageDialog(null,"Hello world","HELLO WORLD",JOptionPane.INFORMATION_MESSAGE);
}
}

***************************************************************
JUST COMPILE AND EXECUTE IT
***************************************************************

Set JTextField selection color

Complete source code below will show you how to set JTextField selection color.

***************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldSelectionColor.java
***************************************************************


import javax.swing.*;

import java.awt.*;

public class SetJTextFieldSelectionColor
{
public static void main(String[]args)
{
JTextField jtf=new JTextField("Select this text");

//Color that will use as JTextField's selection color
//It is base on RGB value
//Red=255
//Green=0
//Blue=0
//You can use color picker at above to get RGB value
Color selectionColor=new Color(255,0,0);

//Set JTextField selection color
jtf.setSelectionColor(selectionColor);

JFrame myWindow=new JFrame("Set JTextField selection color");

myWindow.add(jtf);
myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myWindow.setSize(400,50);
myWindow.setLocationRelativeTo(null);
myWindow.setVisible(true);
}
}


***************************************************************
JUST COMPILE AND EXECUTE IT
***************************************************************

Set JTextField caret color

Complete source code below will show you, how to set JTextField caret color.

****************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldCaretColor.java
****************************************************************


import javax.swing.*;

import java.awt.*;

public class SetJTextFieldCaretColor
{
public static void main(String[]args)
{
JTextField jtf=new JTextField(20);
jtf.setFont(new Font("Verdana",Font.BOLD,34));

JFrame myFrame=new JFrame("Set JTextField caret color");

//Set caret color base on RGB value
//R=255
//G=0
//B=0
//You can get RGB value from color picker at above
jtf.setCaretColor(new Color(255,0,0));

myFrame.setLayout(new FlowLayout());
myFrame.add(jtf);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.pack();
myFrame.setLocationRelativeTo(null);
myFrame.setVisible(true);
}
}


****************************************************************
JUST COMPILE AND EXECUTE IT
****************************************************************

Change default metal look and feel color



*********************************************************************
COMPLETE SOURCE CODE FOR : ChangeMetalLookAndFeelColor.java
*********************************************************************


import javax.swing.plaf.metal.DefaultMetalTheme;

import javax.swing.plaf.metal.MetalLookAndFeel;

import javax.swing.plaf.ColorUIResource;

import javax.swing.*;

import java.awt.FlowLayout;

public class ChangeMetalLookAndFeelColor
{
public ChangeMetalLookAndFeelColor()
{
JFrame.setDefaultLookAndFeelDecorated(true);

MetalLookAndFeel.setCurrentTheme(new OrangeTheme());

JFrame frame=new JFrame("Orange Theme");

frame.getContentPane().setLayout(new FlowLayout());

frame.getContentPane().add(new JButton("JButton"));
frame.getContentPane().add(new JCheckBox("JCheckBox"));
frame.getContentPane().add(new JTextField("JTextField"));

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

public static void main(String[]args)
{
ChangeMetalLookAndFeelColor cmlafm=new ChangeMetalLookAndFeelColor();
}

class OrangeTheme extends DefaultMetalTheme
{
//NEW COLOR FOR METAL LOOK AND FEEL
ColorUIResource primary1=new ColorUIResource(255,215,76);
ColorUIResource primary2=new ColorUIResource(255,198,0);
ColorUIResource primary3=new ColorUIResource(205,162,11);

ColorUIResource secondary1=new ColorUIResource(255,187,57);
ColorUIResource secondary2=new ColorUIResource(255,168,0);
ColorUIResource secondary3=new ColorUIResource(255,214,104);
//NEW COLOR FOR METAL LOOK AND FEEL

protected ColorUIResource getPrimary1()
{
return primary1;
}

protected ColorUIResource getPrimary2()
{
return primary2;
}

protected ColorUIResource getPrimary3()
{
return primary3;
}

protected ColorUIResource getSecondary1()
{
return secondary1;
}

protected ColorUIResource getSecondary2()
{
return secondary2;
}

protected ColorUIResource getSecondary3()
{
return secondary3;
}
}
}


*********************************************************************
JUST COMPILE AND EXECUTE IT
*********************************************************************

Set JSlider tick color

Complete source code below will show you, how to set JSlider tick color. I have tried to find method in JSlider class to set JSlider tick color...but, i can't find it. So i tried to create UI Delegate only for SliderUI that change JSlider tick color. You can try to compile both source code below. Make sure both java file below locate at the same location. JSlider's tick color is set in MyNewMetalSliderUI.java.You can try to change it's color follow what color that you want base on RGB value. After you compile SetJSliderTickColor.java and MyNewMetalSliderUI.java, you try execute SetJSliderTickColor.java. This is because, main method contain in this file.Oooo...before i forget, it's only handle horizontal slider. If you want to make it can use for vertical slider, you can try overwrite method paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y) and paintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, int y) in MetalSliderUI class. You can review it in Java SE API for MetalSliderUI class.

**********************************************************************
COMPLETE SOURCE CODE FOR : MyNewMetalSliderUI.java
**********************************************************************


import javax.swing.*;

import java.awt.*;

import javax.swing.plaf.ColorUIResource;

import javax.swing.plaf.metal.MetalSliderUI;

import javax.swing.plaf.ComponentUI;

public class MyNewMetalSliderUI extends MetalSliderUI
{
// Create our own slider UI
public static ComponentUI createUI(JComponent c )
{
return new MyNewMetalSliderUI();
}

//*******************HORIZONTAL MAJOR TICK*******************
public void paintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
{
int coordinateX=x;

if(slider.getOrientation()==JSlider.HORIZONTAL)
{
//Create color using RGB value(RED=255,GREEN=0,BLUE=0)
//You can use Color picker above to get RGB value for color that you want
Color majorTickColor=new Color(255,0,0);

//Set color that will use to draw MAJOR TICK using created color
g.setColor(majorTickColor);

//Draw MAJOR TICK
g.drawLine(coordinateX,0,coordinateX,tickBounds.height);
}
}
//*******************HORIZONTAL MAJOR TICK*******************

//*******************HORIZONTAL MINOR TICK*******************
public void paintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
{
int coordinateX=x;

if(slider.getOrientation()==JSlider.HORIZONTAL)
{
//Create color using RGB value(RED=12,GREEN=255,BLUE=0)
//You can use Color picker above to get RGB value for color that you want
Color majorTickColor=new Color(12,255,0);

//Set color that will use to draw MINOR TICK using created color
g.setColor(majorTickColor);

//Draw MINOR TICK
g.drawLine(coordinateX,0,coordinateX,tickBounds.height/2);
}
}
//*******************HORIZONTAL MINOR TICK*******************
}


**********************************************************************
JUST COMPILE
**********************************************************************

**********************************************************************
COMPLETE SOURCE CODE FOR : SetJSliderTickColor.java
**********************************************************************

import javax.swing.*;

import java.awt.*;

public class SetJSliderTickColor
{
public SetJSliderTickColor()
{
//Create slider using JSlider
JSlider mySlider=new JSlider();

//Set major tick spacing to 10
mySlider.setMajorTickSpacing(10);

//Set minor tick spacing to 1
mySlider.setMinorTickSpacing(1);

//Make slider's numbers visible
mySlider.setPaintLabels(true);

//Make slider's ticks visible
mySlider.setPaintTicks(true);

//Create a window using JFrame with title ( Set JSlider tick color )
JFrame frame=new JFrame("Set JSlider tick color");

//Set JFrame layout to FlowLayout
frame.setLayout(new FlowLayout());

//Add created JSlider into JFrame
frame.add(mySlider);

//Set JFrame's default close operation
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(500,300);

//Set JFrame locate at center of screen
frame.setLocationRelativeTo(null);

//Make JFrame visible
frame.setVisible(true);
}

public static void main(String[]args)
{
/***********Set our own UI Delegate for Slider*************/
UIManager uim=new UIManager();

//MyNewMetalSliderUI contain settings that use to change tick color
uim.put("SliderUI","MyNewMetalSliderUI");
/***********Set our own UI Delegate for Slider*************/

SetJSliderTickColor sjstc=new SetJSliderTickColor();
}
}


**********************************************************************
JUST COMPILE AND EXECUTE
**********************************************************************

Set ToolTipText background color

Complete source code below, will show you how to set ToolTipText background color.

**************************************************************************
COMPLETE SOURCE CODE FOR : SetToolTipTextBackgroundColor.java
**************************************************************************


import javax.swing.UIManager;
import javax.swing.JFrame;
import javax.swing.JButton;

import java.awt.FlowLayout;
import java.awt.Color;

public class SetToolTipTextBackgroundColor
{
/**
*Create a button with text ( Put your cursor on me )
*/
JButton button=new JButton("Put your cursor on me");

//Create a window using JFrame with text ( Set ToolTipText background color )
JFrame frame=new JFrame("Set ToolTipText background color");

public SetToolTipTextBackgroundColor()
{
//Create a color base on RGB value
//You can get your color value base on RGB using Color picker at above
//R=204 G=0 B=153
Color backgroundColor=new Color(204,0,153);

//Create UIManager
UIManager uim=new UIManager();

//Set tooltiptext background color using created Color
uim.put("ToolTip.background",backgroundColor);

//Set tooltiptext for created button
button.setToolTipText("I am a button");

frame.setLayout(new FlowLayout());
frame.add(button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

public static void main(String[]args)
{
SetToolTipTextBackgroundColor stttbc=new SetToolTipTextBackgroundColor();
}
}


**************************************************************************
JUST COMPILE AND EXECUTE IT
**************************************************************************

Set ToolTipText text color

Complete source code below, will show you how to set ToolTipText text color.

************************************************************************
COMPLETE SOURCE CODE FOR : SetToolTipTextColor.java
************************************************************************


import javax.swing.UIManager;
import javax.swing.JFrame;
import javax.swing.JButton;

import java.awt.FlowLayout;
import java.awt.Color;

public class SetToolTipTextColor
{
/**
*Create a button with text ( Put your cursor on me )
*/
JButton button=new JButton("Put your cursor on me");

//Create a window using JFrame with title ( Set ToolTipText text color )
JFrame frame=new JFrame("Set ToolTipText text color");

public SetToolTipTextColor()
{
//Create a color base on RGB value
//You can get your color value base on RGB using Color picker at above
//R=255 G=255 B=255 is RGB value for white
Color textColor=new Color(255,255,255);

//Create UIManager
UIManager uim=new UIManager();

//Set tooltiptext text color using created Color
uim.put("ToolTip.foreground",textColor);

//Set tooltiptext for created button
//So, it's tooltiptext text color will be WHITE
button.setToolTipText("I am a button");

frame.setLayout(new FlowLayout());
frame.add(button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

public static void main(String[]args)
{
SetToolTipTextColor stttc=new SetToolTipTextColor();
}
}


************************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************************

Set JButton text color using UIManager

Complete source code below will show you, how to set JButton text color using UIManager. When you set JButton text color using this style, it will make all JButton in your program will have same text color. So, if you want to set only one text color for JButton, i suggest you click here.

**********************************************************************
COMPLETE SOURCE CODE FOR : SetJButtonForegroundColorUseUiManager.java
**********************************************************************


import javax.swing.UIManager;

import javax.swing.plaf.ColorUIResource;

import javax.swing.*;

import java.awt.*;

public class SetJButtonForegroundColorUseUiManager
{
public static void main(String[]args)
{
/*
*Create color base on RGB color model
*that will use as JButton foreground color.
*Red=255
*Green=0
*Blue=0
*/
Color foregroundColor=new Color(255,0,0);

//Set JButton foreground color
UIManager.put("Button.foreground",new ColorUIResource(foregroundColor));

//Create a window using JFrame with title ( Set JButton foreground color using UIManager )
JFrame frame=new JFrame("Set JButton foreground color using UIManager");

//Create two button
JButton button1=new JButton("Button 1");
JButton button2=new JButton("Button 2");

//Set JFrame layout to FlowLayout
frame.setLayout(new FlowLayout());

//Add created button into frame
frame.add(button1);
frame.add(button2);

//Set JFrame default close operation
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(400,400);

//Make JFrame locate at center
frame.setLocationRelativeTo(null);

//Make JFrame visible
frame.setVisible(true);
}
}


**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************

Set JButton gradient color

Complete source code below will show you, how to change JButton default gradient color.



******************************************************************
COMPLETE SOURCE CODE FOR : SetJButtonGradientColor.java
******************************************************************


import java.util.LinkedList;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.UIManager;

import javax.swing.plaf.ColorUIResource;

public class SetJButtonGradientColor
{
public static void main(String[]args)
{
//Create UIManager object
UIManager manager=new UIManager();


//IMPORTANT : Key to know : "Button.gradient"

//Set color base on RGB
//You can get RGB value for your color at "Color picker" at above

//******************************************************
//Create linked list that will store all gradient information
//You can try to understand it by change it's value
LinkedList<Object> a=new LinkedList<Object>();
a.add(0.3);
a.add(0.3);

//First colour : R=2,G=208,B=206
a.add(new ColorUIResource(2,208,206));

//Second colour : R=136,G=255,B=254
a.add(new ColorUIResource(136,255,254));

//Third colour : R=0,G=142,B=140
a.add(new ColorUIResource(0,142,140));
//******************************************************

//Set Button.gradient key with new value
manager.put("Button.gradient",a);

//Create a button using JButton with text ( BUTTON )
JButton button=new JButton("BUTTON");

//Create a window using JFrame with title ( JButton gradient color )
JFrame frame=new JFrame("JButton gradient color");

//Add created button into JFrame
frame.add(button);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(330,80);

//Make JFrame visible. So we can see it.
frame.setVisible(true);
}
}


******************************************************************
JUST COMPILE AND EXECUTE IT
******************************************************************

Set JTextArea background color to JFrame default color

Complete source code below will show you, how to set JTextArea background color same to JFrame default color.

**********************************************************************
COMPLETE SOURCE CODE FOR : SetJTextAreaBackgroundColorToJFrameColor.java
**********************************************************************


import javax.swing.*;

import java.awt.Color;

public class SetJTextAreaBackgroundColorToJFrameColor
{
public static void main(String[]args)
{
//Create a window using JFrame with title ( Set JTextArea background color to JFrame color )
JFrame frame=new JFrame("Set JTextArea background color to JFrame color");

//Get JFrame background color
Color jframeColor=frame.getBackground();

//Create a text area with initial text ( Put your text here )
JTextArea textArea=new JTextArea("Put your text here");

//Set text area background color same to JFrame background color
textArea.setBackground(jframeColor);

//Add created text area into JFrame
frame.add(textArea);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(600,500);

//Make JFrame locate at center on screen
frame.setLocationRelativeTo(null);

//Make JFrame visible
frame.setVisible(true);
}
}


**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************

Get default JFrame background color

Complete source code below will show you, how to get default JFrame background color and after that, it will print RED,GREEN,BLUE(RGB) value for the color.

****************************************************************
COMPLETE SOURCE CODE FOR : GetDefaultJFrameBackgroundColor.java
****************************************************************


import javax.swing.JFrame;

import java.awt.Color;

public class GetDefaultJFrameBackgroundColor
{
public static void main(String[]args)
{
//Create a window using JFrame
JFrame frame=new JFrame();

//Get JFrame background color using method getBackground()
Color frameBackgroundColor=frame.getBackground();

//Get RED value from color
int redValue=frameBackgroundColor.getRed();

//Get GREEN value from color
int greenValue=frameBackgroundColor.getGreen();

//Get BLUE value from color
int blueValue=frameBackgroundColor.getBlue();

//Print RGB value that we get
System.out.println("R : "+redValue);
System.out.println("G : "+greenValue);
System.out.println("B : "+blueValue);

//You can check what color that match the RGB value that we get using 'Color picker' at above
}
}


****************************************************************
JUST COMPILE AND EXECUTE IT
****************************************************************

Get default JPanel background color

Complete source code below will show you, how to get default JPanel background color and after that, it will print RED,GREEN,BLUE(RGB) value for the color.

******************************************************************
COMPLETE SOURCE CODE FOR : GetDefaultJPanelBackgroundColor.java
******************************************************************


import javax.swing.JPanel;

import java.awt.Color;

public class GetDefaultJPanelBackgroundColor
{
public static void main(String[]args)
{
//Create a panel using JPanel
JPanel panel=new JPanel();

//Get panel background color using method getBackground()
Color panelBackgroundColor=panel.getBackground();

//Get RED value from color
int redValue=panelBackgroundColor.getRed();

//Get GREEN value from color
int greenValue=panelBackgroundColor.getGreen();

//Get BLUE value from color
int blueValue=panelBackgroundColor.getBlue();

//Print RGB value that we get
System.out.println("R : "+redValue);
System.out.println("G : "+greenValue);
System.out.println("B : "+blueValue);

//You can check what color that match the RGB value that we get using 'Color picker' at above
}
}


******************************************************************
JUST COMPILE AND EXECUTE IT
******************************************************************

Get default JLabel background color

Complete source code below will show you, how to get default JLabel background color and after that, it will print RED,GREEN,BLUE(RGB) value for the color.

*****************************************************************
COMPLETE SOURCE CODE FOR : GetDefaultJLabelBackgroundColor.java
*****************************************************************


import javax.swing.JLabel;

import java.awt.Color;

public class GetDefaultJLabelBackgroundColor
{
public static void main(String[]args)
{
//Create a label using JLabel
JLabel label=new JLabel();

//Get label background color using method getBackground()
Color labelBackgroundColor=label.getBackground();

//Get RED value from color
int redValue=labelBackgroundColor.getRed();

//Get GREEN value from color
int greenValue=labelBackgroundColor.getGreen();

//Get BLUE value from color
int blueValue=labelBackgroundColor.getBlue();

//Print RGB value that we get
System.out.println("R : "+redValue);
System.out.println("G : "+greenValue);
System.out.println("B : "+blueValue);

//You can check what color that match the RGB value that we get using 'Color picker' at above
}
}


*****************************************************************
JUST COMPILE AND EXECUTE IT
*****************************************************************

Set JButton select color

Source code below will show you, how to set JButton select color base on RGB. You can get RGB value for your color using "Color picker" at above.

**********************************************************************
COMPLETE SOURCE CODE FOR : SetJButtonSelectColor.java
**********************************************************************


import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.UIManager;

import javax.swing.plaf.ColorUIResource;

public class SetJButtonSelectColor
{
public static void main(String[]args)
{
//Create UIManager object
UIManager manager=new UIManager();


//Key to know : "Button.select"

//Set color base on RGB
//You can get RGB value for your color at "Color picker" at above
//R=255
//G=0
//B=0
manager.put("Button.select",new ColorUIResource(255,0,0));

//Create a button using JButton with text ( CLICK ME AND SEE WHAT COLOR )
JButton button=new JButton("CLICK ME AND SEE WHAT COLOR");

//Create a window using JFrame with title ( JButton select color )
JFrame frame=new JFrame("JButton select color");

//Add created button into JFrame
frame.add(button);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(300,80);

//Make JFrame visible. So we can see it.
frame.setVisible(true);
}
}


**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************

Set JPasswordField text color

Source code below will show you, how to set JPasswordField text color base on RGB. You can get RGB value for your color using "Color picker" at above.

**************************************************************************
COMPLETE SOURCE CODE FOR : SetJPasswordFieldTextColor.java
**************************************************************************


import javax.swing.JPasswordField;
import javax.swing.JFrame;

import java.awt.Color;
import java.awt.FlowLayout;

public class SetJPasswordFieldTextColor
{
public static void main(String[]args)
{
//Create password field using JPasswordField
JPasswordField passwordField=new JPasswordField(10);

//Create JFrame with title ( Set JPasswordField text color )
JFrame frame=new JFrame("Set JPasswordField text color");

//Set JFrame layout to FlowLayout
frame.setLayout(new FlowLayout());

//Set color base on RGB
//You can get RGB value for your color at "Color picker" at above
//R=255
//G=0
//B=0
Color color=new Color(255,0,0);

//Set JPasswordField text color to color that you choose
passwordField.setForeground(color);

//Add JPasswordField into JFrame
frame.add(passwordField);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(500,300);

//Make JFrame visible
frame.setVisible(true);
}
}


**************************************************************************
JUST COMPILE AND EXECUTE IT
**************************************************************************

Set JPanel background color

Source code below will show you, how to set JPanel background color base on RGB. You can get RGB value for your color using "Color picker" at above.

**********************************************************************
COMPLETE SOURCE CODE FOR : SetJPanelBackgroundColor.java
**********************************************************************


import javax.swing.JPanel;
import javax.swing.JFrame;

import java.awt.Color;

public class SetJPanelBackgroundColor
{
public static void main(String[]args)
{
//Create panel using JPanel
JPanel panel=new JPanel();

//Create JFrame with title ( Set JPanel background color )
JFrame frame=new JFrame("Set JPanel background color");

//Set color base on RGB
//You can get RGB value for your color at "Color picker" at above
//R=255
//G=0
//B=0
Color color=new Color(255,0,0);

//Set JPanel background color to color that you choose
panel.setBackground(color);

//Add JPanel into JFrame
frame.add(panel);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(500,300);

//Make JFrame visible
frame.setVisible(true);
}
}


**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************

Set JButton text color

Source code below will show you, how to set JButton text color base on RGB. You can get RGB value for your color using "Color picker" at above.

*************************************************************************
COMPLETE SOURCE CODE FOR : SetJButtonTextColor.java
*************************************************************************


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

import java.awt.Color;
import java.awt.FlowLayout;

public class SetJButtonTextColor
{
public static void main(String[]args)
{
//Create button using JButton
JButton button=new JButton("Click me");

//Create JFrame with title ( Set JButton text color )
JFrame frame=new JFrame("Set JButton text color");

//Set JFrame layout to FlowLayout
frame.setLayout(new FlowLayout());

//Set color base on RGB
//You can get RGB value for your color at "Color picker" at above
//R=255
//G=0
//B=0
Color color=new Color(255,0,0);

//Set JButton text color to color that you choose
button.setForeground(color);

//Add JButton into JFrame
frame.add(button);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(500,300);

//Make JFrame visible
frame.setVisible(true);
}
}


*************************************************************************
JUST COMPILE AND EXECUTE IT
*************************************************************************

Set JButton background color

Source code below will show you, how to set JButton background color base on RGB. You can get RGB value for your color using "Color picker" at above.

**************************************************************************
COMPLETE SOURCE CODE FOR : SetJButtonBackgroundColor.java
**************************************************************************


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

import java.awt.Color;
import java.awt.FlowLayout;

public class SetJButtonBackgroundColor
{
public static void main(String[]args)
{
//Create button using JButton
JButton button=new JButton("Click me");

//Create JFrame with title ( Set JButton background color )
JFrame frame=new JFrame("Set JButton background color");

//Set JFrame layout to FlowLayout
frame.setLayout(new FlowLayout());

//Set color base on RGB
//You can get RGB value for your color at "Color picker" at above
//R=255
//G=0
//B=0
Color color=new Color(255,0,0);

//Set JButton background color to color that you choose
button.setBackground(color);

//Add JButton into JFrame
frame.add(button);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(500,300);

//Make JFrame visible
frame.setVisible(true);
}
}


**************************************************************************
JUST COMPILE AND EXECUTE IT
**************************************************************************

Set JTextField text color

Source code below will show you, how to set JTextField text color base on RGB. You can get RGB value for your color using "Color picker" at above.

*******************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldTextColor.java
*******************************************************************


import javax.swing.JTextField;
import javax.swing.JFrame;

import java.awt.Color;
import java.awt.FlowLayout;

public class SetJTextFieldTextColor
{
public static void main(String[]args)
{
//Create text field using JTextField
JTextField textField=new JTextField(10);

//Create JFrame with title ( Set JTextField text color )
JFrame frame=new JFrame("Set JTextField text color");

//Set JFrame layout to FlowLayout
frame.setLayout(new FlowLayout());

//Set color base on RGB
//You can get RGB value for your color at "Color picker" at above
//R=255
//G=0
//B=0
Color color=new Color(255,0,0);

//Set JTextField text color to color that you choose
textField.setForeground(color);

//Add JTextField into JFrame
frame.add(textField);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(500,300);

//Make JFrame visible
frame.setVisible(true);
}
}


*******************************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************************

RELAXING NATURE VIDEO