Changing JTextField Color to Be Transparent Color in Java GUI

Friday, July 29, 2011

How to change JTextField Color to Be Transparent Color in Java GUI, How to Make Transparent JTextField and same with background frame, How can I make Transparent JTextField, Trick to make transparent JTextField
At the time I make a program in java gui, I got the idea to adjust the colors in JTextField with a background color on the frame. It looks very nice if we have a background image, and customize it.

Cause of that, I've looked for ways to customize the background color of the JTextField. After much looking for a reference, I finally found a powerful way to do this programming trick.

good luck to try trick "way to change the color to be transparent JTextField"

You'll get a frame like this :


In that picture, You can see the background color of frame is YELLOW, And Both of JTextField Yellow too. I'll explain about source of program.
________________________________________________
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Log extends JFrame {

public static void main(String[] args) {
Log frameTabel = new Log();
}

JButton blogin = new JButton("Login");
JPanel panel = new JPanel();
JTextField txuser = new JTextField(15);
JPasswordField pass = new JPasswordField(15);

Log(){
super("Login Autentification");
setSize(300,200);
setLocation(500,280);
panel.setLayout (null);
panel.setBackground(Color.YELLOW);

txuser.setBounds(70,30,150,20);
txuser.setOpaque(false);
pass.setBounds(70,65,150,20);
pass.setOpaque(false);
blogin.setBounds(110,100,80,20);

panel.add(blogin);
panel.add(txuser);
panel.add(pass);

getContentPane().add(panel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
actionlogin();
}

public void actionlogin(){
blogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String puname = txuser.getText();
String ppaswd = pass.getText();
if(puname.equals("test") && ppaswd.equals("12345")) {
newframe regFace =new newframe();
regFace.setVisible(true);
dispose();
} else {

JOptionPane.showMessageDialog(null,"Wrong Password / Username");
txuser.setText("");
pass.setText("");
txuser.requestFocus();
}

}
});
}
}
_______________________________________________________

Both of JTextField named as "txuser" and "pass". Source Code which make they transparent are :

txuser.setOpaque(false); and
pass.setOpaque(false);

and Source Code wich make Yellow Background is :

panel.setBackground(Color.YELLOW);

You can change the color you like. Good Luck... and Thanks for visit us....

By Programming Tricks

2 comments:

sasitamil said...

It seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.

Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training

sasitamil said...

This is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb.
This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolites festivity to pity. I appreciated what you ok extremely here 


Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training

Post a Comment

 
 
 
 
Copyright © Programming Tricks