textfield placeholder code example
Example 1: placeholder textfield flutter
TextField(
onChanged: (value) {
},
decoration: InputDecoration(
hintText: 'Enter your password.',
contentPadding:
EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.lightBlueAccent, width: 1.0),
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.lightBlueAccent, width: 2.0),
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
),
),
Example 2: 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 3: uitextfield placeholder text
textField.placeholder = "placeholderString"