Alhamdulillah. This is a blog of all digital works by Mohd Anis Bin Azinan (Since 2008).
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
**********************************************************************
**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************
**********************************************************************
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
*************************************************************************
*************************************************************************
JUST COMPILE AND EXECUTE IT
*************************************************************************
*************************************************************************
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
**************************************************************************
**************************************************************************
JUST COMPILE AND EXECUTE IT
**************************************************************************
**************************************************************************
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
*******************************************************************
*******************************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************************
*******************************************************************
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
*******************************************************************
Set JTextField background color
Source code below will show you, how to set JTextField background color base on RGB. You can get RGB value for your color using "Color picker" at above.
*********************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldBackgroundColor.java
*********************************************************************
*********************************************************************
JUST COMPILE AND EXECUTE IT
*********************************************************************
*********************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldBackgroundColor.java
*********************************************************************
import javax.swing.JTextField;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.FlowLayout;
public class SetJTextFieldBackgroundColor
{
public static void main(String[]args)
{
//Create text field using JTextField
JTextField textField=new JTextField(10);
//Create JFrame with title ( Set JTextField background color )
JFrame frame=new JFrame("Set JTextField 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 JTextField background color to color that you choose
textField.setBackground(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
*********************************************************************
Set JTextArea text color
Source code below will show you, how to set JTextArea text color base on RGB. You can get RGB value for your color using "Color picker" at above.
********************************************************************
COMPLETE SOURCE CODE FOR : SetJTextAreaTextColor.java
********************************************************************
********************************************************************
JUST COMPILE AND EXECUTE IT
********************************************************************
********************************************************************
COMPLETE SOURCE CODE FOR : SetJTextAreaTextColor.java
********************************************************************
import javax.swing.JTextArea;
import javax.swing.JFrame;
import java.awt.Color;
public class SetJTextAreaTextColor
{
public static void main(String[]args)
{
//Create text area using JTextArea
JTextArea textArea=new JTextArea();
//Create JFrame with title ( Set JTextArea text color )
JFrame frame=new JFrame("Set JTextArea text 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 JTextArea text color to color that you choose
textArea.setForeground(color);
//Add JTextArea into JFrame
frame.add(textArea);
//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 JTextArea background color
Source code below will show you, how to set JTextArea background color base on RGB. You can get RGB value for your color using "Color picker" at above.
**********************************************************************
COMPLETE SOURCE CODE FOR : SetJTextAreaBackgroundColor.java
**********************************************************************
**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************
**********************************************************************
COMPLETE SOURCE CODE FOR : SetJTextAreaBackgroundColor.java
**********************************************************************
import javax.swing.JTextArea;
import javax.swing.JFrame;
import java.awt.Color;
public class SetJTextAreaBackgroundColor
{
public static void main(String[]args)
{
//Create text area using JTextArea
JTextArea textArea=new JTextArea();
//Create JFrame with title ( Set JTextArea background color )
JFrame frame=new JFrame("Set JTextArea 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 JTextArea background color to color that you choose
textArea.setBackground(color);
//Add JTextArea into JFrame
frame.add(textArea);
//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 JLabel text color
Source code below will show you, how to set JLabel text color base on RGB. You can get RGB value for your color using "Color picker" at above.
*****************************************************************
COMPLETE SOURCE CODE FOR : SetJLabelTextColor.java
*****************************************************************
*****************************************************************
JUST COMPILE AND EXECUTE IT
*****************************************************************
*****************************************************************
COMPLETE SOURCE CODE FOR : SetJLabelTextColor.java
*****************************************************************
import javax.swing.JLabel;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.FlowLayout;
public class SetJLabelTextColor
{
public static void main(String[]args)
{
//Create label with text HI using JLabel
JLabel label=new JLabel("HI");
//Create JFrame with title ( Set JLabel text color )
JFrame frame=new JFrame("Set JLabel 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 JLabel text color to color that you choose
label.setForeground(color);
//Add JLabel into JFrame
frame.add(label);
//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 JLabel background color
Source code below will show you, how to set JLabel background color base on RGB. You can get RGB value for your color using "Color picker" at above.
************************************************************************
COMPLETE SOURCE CODE FOR : SetJLabelBackgroundColor.java
************************************************************************
************************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************************
************************************************************************
COMPLETE SOURCE CODE FOR : SetJLabelBackgroundColor.java
************************************************************************
import javax.swing.JLabel;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
public class SetJLabelBackgroundColor extends JLabel
{
//Create JFrame with title ( Set JLabel background color )
JFrame frame=new JFrame("Set JLabel 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);
public SetJLabelBackgroundColor()
{
//Set text for JLabel
setText("Set JLabel Background Color");
//Set JFrame layout to FlowLayout
frame.setLayout(new FlowLayout());
//Add JLabel into JFrame
frame.add(this);
//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);
}
//Fill background color to JLabel
public void paint(Graphics g)
{
g.setColor(color);
g.fillRect(0,0,getWidth(),getHeight());
super.paint(g);
}
public static void main(String[]args)
{
SetJLabelBackgroundColor sjlbc=new SetJLabelBackgroundColor();
}
}
************************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************************
Subscribe to:
Posts (Atom)