How To Create A Placeholder String Using Java NetBeans
In this Java Tutorial we will see How To Make A JTextField With A PlaceHolder Text Using Events => jTextFieldFocusGained + jTextFieldFocusLost In Java NetBeans .
Project Source Code:
private void jTextField1FocusGained(java.awt.event.FocusEvent evt) {
if(jTextField1.getText().trim().toLowerCase().equals("email")){
jTextField1.setText("");
jTextField1.setForeground(Color.YELLOW);
}
}
private void jTextField1FocusLost(java.awt.event.FocusEvent evt) {
if(jTextField1.getText().trim().equals("") || jTextField1.getText().trim().toLowerCase().equals("email")){
jTextField1.setText("Email");
jTextField1.setForeground(new Color(236, 240, 241));
}
}
private void jTextField2FocusGained(java.awt.event.FocusEvent evt) {
if(jTextField2.getText().trim().toLowerCase().equals("username")){
jTextField2.setText("");
jTextField2.setForeground(Color.YELLOW);
}
}
private void jTextField2FocusLost(java.awt.event.FocusEvent evt) {
if(jTextField2.getText().trim().equals("") || jTextField2.getText().trim().toLowerCase().equals("username")){
jTextField2.setText("Username");
jTextField2.setForeground(new Color(236, 240, 241));
}
}
OutPut:
Download Projects Source Code