17 Sept 2012

Set JPasswordField Background Color in java swings


import javax.swing.JPasswordField;  
import javax.swing.JFrame;  
import java.awt.Color;  
  
public class SetJPasswordFieldBackgroundColor  
{  
public static void main(String[]args)  
{  
 //Create password field with number of columns equal to 10  
 JPasswordField passwordField=new JPasswordField(10);  
  
 //Create JFrame with title ( Set JPasswordField background color )  
 JFrame frame=new JFrame("Set JPasswordField 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 JPasswordField background color to color that you choose  
 passwordField.setBackground(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,65);  
  
 //Make JFrame visible  
 frame.setVisible(true);  
}  
}  

0 comments:

Post a Comment