【问题标题】:How do I get a JTextFields Action Command?如何获得 JTextFields 操作命令?
【发布时间】:2015-01-30 11:17:57
【问题描述】:

我有一个 jTextField,我设置了一个命令字符串,但是我希望能够在 不必触发事件的情况下检索它。

JTextField tf = new JTextField();
tf.setActionCommand("command");

String cmd = tf.getActionCommand();  <----   ???????

非常感谢!

【问题讨论】:

  • 我设置的动作命令字符串。在 JButton 上,您有 .setActionCommand 和 .getActionCommand 来设置和获取操作命令字符串,但使用 JTextField 只有一个 setActionCommand。我知道您可以通过触发事件来获取 JTextField 的操作命令字符串,但我想要它而不必这样做。
  • 显而易见的问题当然是你为什么想要这个。什么可能的用例需要这个。除此之外,您可以考虑使用 putClientPropertygetClientProperty 方法,每个 JComponent 都有用于您的目的。

标签: java swing jtextfield


【解决方案1】:

正如您所发现的,JTextField 不提供 getActionCommand()。

看看:

Uses of getActionCommand()

【讨论】:

    猜你喜欢
    • 2017-03-15
    • 2020-04-21
    • 2013-09-02
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 2013-02-18
    • 2012-06-30
    • 1970-01-01
    相关资源
    最近更新 更多