When my application loads, which is made using netbeans, the first JTextField is automatically focused, and in this JTextField, I have written “Enter your Username”, it will go away when the user clicks on this field, but when the application is loaded, this field is focused, means I can’t see “Enter your Username”, how to unfocus it on startup ?
When my application loads, which is made using netbeans, the first JTextField is automatically
Share
A log-in would be best done in a modal dialog, but that introduces problems in that the method
requestFocusInWindow()must be called after the component is visible, but that is blocked by the fact the dialog is modal!This example uses Rob Camick’s
RequestFocusListener(as presented in Dialog Focus) to manage focus after the dialog is visible.Note: That is how it appears before the user does anything. The password field is focused by default.