Can a value from a JTextField be forced into the ValueModel (JGoodies)

筅森魡賤 提交于 2019-12-06 07:11:35

I hope I am understanding your question correctly.

You need to get the text in the text field and set it in the 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();
    }     
 }); 

I looked through the JGoodies API (should have done this sooner) and found an unexpected static call, Bindings.commitImmediately()

If I call this method before my call to trigger.triggerCommit(), everything works as expected :)

Create a text field that commits on each key typed instead of when focus is lost:

BasicComponentFactory.createTextField(firstNameAdapter, false);

Also, you should consider architecting your program to not use buffered models. I find that they make things more complicated and tricky, and think I saw Karsten Lentzsch recommending not to use them as well in a mailing list.

The most useful way for me to learn JGoodies was to look at the tutorial code for the JGoodies binding and validation libraries.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!