Pages

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
**************************************************************************
Related Posts Plugin for WordPress, Blogger...