How to refer to the theme item instance from within an action method in StateMachine?

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

  •  10-06-2023
  •  | 
  •  

سؤال

Right now,

i am casting it down to its type. If I use it in an ActionListener, I'm declaring it as final:

final TextField tf = ((TextField)c); 
tf = tf.getText();

Here,

Component c 

is the parameter of the action method.

There doesn't seem to be a method in Component or in anyone of the descendants returning the component instance. The name of the component in Designer interface didn't work either.

One other i can think of is using ActionEvent.getSource(). I haven't tried it yet-- there should be a more direct way(?)

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

المحلول

Use:

TextField t = findNameOfMyTextField(c);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top