Reputation: 3
Here is my code in the event methods:
private void txtCampusSearchFocusGained(java.awt.event.FocusEvent evt) {
this.txtCampusSearch.setText(null);
}
private void txtCampusSearchFocusLost(java.awt.event.FocusEvent evt) {
this.txtCampusSearch.setText("Search...");
}
private void txtBuildingSearchFocusGained(java.awt.event.FocusEvent evt) {
this.txtCampusSearch.setText(null);
}
private void txtBuildingSearchFocusLost(java.awt.event.FocusEvent evt) {
this.txtCampusSearch.setText("Search...");
}
However when I actually run the application these methods don't seem to be activated when focus is gained / lost. Application Running
Upvotes: 0
Views: 694
Reputation: 989
You have to add a focus listener to your textfield.
JTextField textField = new JTextField("A TextField");
textField.addFocusListener(new MyFocusListener());
https://docs.oracle.com/javase/tutorial/uiswing/events/focuslistener.html
Upvotes: 2