How do I determine component with focus in a codenameone container?

StackOverflow https://stackoverflow.com/questions/23412109

  •  13-07-2023
  •  | 
  •  

سؤال

I am building a json editor in codenameone. In my current design I need to insert or remove components that have focus when a menu command is pressed. So for instance if i have TextFields inside a Container , I need to determine which textfield has focus when I press the insert menu option so that I can insert another component there.

هل كانت مفيدة؟

المحلول

On the current form (you can get the current form using Display.getInstance().getCurrent()) invoke getFocused(). You can also bind a focus listener using addFocusListener on the form or on the component you want to track.

Notice that with touch device the concept of focus isn't quite the same since focus isn't marked on such devices.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top