简体   繁体   中英

Listener only for the first click on JTextField

Is there a java event for JTextField do like : if the cursor already was in the JTextField and MousePressed = do nothing if click on the JTextField for the first time = do things I have been used , MousePressed(java.awt.event.MouseEvent evt) but this not exactly what I want. thank you

You can implement your own custom logic:

  • Store a "flag" like global boolean variable:
     boolean alreadyClicked = false
  • Each time you click the JTextField check (and toggle) that variable:
     if(!alreadyClicked) { alreadyClicked = true; // do your work }
  • When focusing out from that field toggle variable again to:
     alreadyClicked = false;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM