gpt4 book ai didi

java - 可以将来自 JTextField 的值强制放入 ValueModel (JGoodies)

转载 作者:行者123 更新时间:2023-11-29 09:23:16 25 4
gpt4 key购买 nike

我有这个代码:

this.trigger = new Trigger();
this.presentationModel = new PresentationModel(this.personBean, this.trigger);
final ValueModel firstNameAdapter = presentationModel.getBufferedModel("firstName");
final JTextField firstNameTextField = BasicComponentFactory.createTextField(firstNameAdapter);

firstNameTextField.addActionListener(new ActionListener() 
{
@Override
public void actionPerformed(ActionEvent e)
{
trigger.triggerCommit();
}
});

因此,当我按下 JTextField 上的输入按钮时,我希望我的 ValueModel 类中的值与我的 JTextField< 中的值相同。这不会发生,除非我在 JTextField 外部单击,然后返回到 JTextField 内部,然后按回车键。如果我只是输入文本并按回车键,ValueModel 不会获得更新后的值。我被困在这个问题上,有人可以帮忙吗?

顺便说一句,我首先使用这个链接来找出 JGoodies:JGoodies Tutorial

最佳答案

希望我能正确理解您的问题。

您需要获取文本字段中的文本并将其设置在 ValueModel 中。

firstNameTextField.addActionListener(new ActionListener()      
{
@Override
public void actionPerformed(ActionEvent e)
{
//this get the text from the text field
String firstName = firstNameTextField.getText();

//now write your code to set the firstname into the ValueModel


trigger.triggerCommit();
}
});

关于java - 可以将来自 JTextField 的值强制放入 ValueModel (JGoodies),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4727028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com