简体   繁体   English

如何在 Java 中查找视图的当前 JTextField 的名称?

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

I have a view in Java where I am entering data in JTextfields.我在 Java 中有一个视图,我在 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.它确实返回当前 JTextField 的文本,但是当我调用以下行时,它返回 null。

c.getName();

Why is this happening and how should I solve this?为什么会发生这种情况,我该如何解决?

You never set a name for the text field in the first place.您从一开始就不会为文本字段设置名称。 You can't .getName if you haven't .setName.如果你没有 .setName,你就不能 .getName。

Cheers!干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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