placeholder input html code example
Example 1: jtextfield placeholder
txtField = new JTextField();
txtField.setForeground(Color.LIGHT_GRAY);
txtField.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
if(txtField.getText().trim().equals("Hello World")) {
txtField.setText("");
}
txtField.setForeground(Color.BLACK);
}
@Override
public void focusLost(FocusEvent e) {
if(txtField.getText().trim().equals("")) {
txtField.setText("Hello World");
}
txtField.setForeground(Color.LIGHT_GRAY);
}
});
Example 2: placeholder html
<input placeholder="text">
Example 3: placeholder text html
<input placeholder="e.g. Name">
Example 4: input text hint
placeholder="123-45-678"