How to find the name of current JTextField of a View in Java?

493 Views Asked by At

I have a view in Java where I am entering data in JTextfields. A thread is running in parallel that gets input from a keypad by using snippets of code written below. Now whenever I call

JTextField c = (JTextField) manager.getFocusOwner();
c.getText();

where the manager is

KeyboardFocusManager.getCurrentFocusManager();

It does return the text of the current JTextField but when I call the following line, it returns null.

c.getName();

Why is this happening and how should I solve this?

1

There are 1 best solutions below

5
Jacob B. On BEST ANSWER

You never set a name for the text field in the first place. You can't .getName if you haven't .setName.

Cheers!