java - Different Enter and mouse click event -
i have button call method, in method call method connect db , return results, if results positive, change labels , make button enabled, , if results negative, button still disabled
the problem is, have set in tf keytyped event, if type new in it, disable btneditar:
public void keytyped(keyevent e) { btneditar.setenabled(false); btndeletar.setenabled(false); }
i dont want event "capture" enter disable button there way or have think logic way?
as others have pointed out, there other ways besides using keylistener
. respond original attempt below. keylistener
functional , easy tool use job.
use keypressed
instead of keytyped
, , you'll have valid key code can use ignore enter presses:
public void keypressed(keyevent e) { // not keytyped! if (e.getkeycode() != keyevent.vk_enter) { btneditar.setenabled(false); btndeletar.setenabled(false); } }
if insist on using keytyped
reason, you won't have key code available, can cover cases checking character newline or carriage return:
public void keytyped(keyevent e) { if (e.getkeychar() != 13 && e.getkeychar() != 10) { btneditar.setenabled(false); btndeletar.setenabled(false); } }
Comments
Post a Comment