Reputation: 10333
I am using JGoodies Binding on a JTextField like so:
trigger = new Trigger();
PresentationModel<SpectralControlsModel> adapter = new PresentationModel<SpectralControlsModel>(model, trigger);
ValueModel valueModelStartingSampleJTextField = adapter.getBufferedModel("startingSample");
startingSampleJTextField = BasicComponentFactory.createLongField(valueModelStartingSampleJTextField);
setupValueModelListener(valueModelStartingSampleJTextField, startingSampleJTextField);
I have a keyListener on the JTextField that commits data to the model when the "enter" key is pushed.
The problem is when I enter in a new number in the JTextField and hit enter, the model gets the old value, even though I call trigger.triggerCommit(). If I enter a new number and then click something else, lose focus on the JTextField, and then gain focus again, then the new value ends up in the model as expected.
Let me know if I described the problem clearly enough, it is very strange behaviour and I need to get to the bottom of it, thanks.
UPDATE I went to this Java2s.com JGoodies Example and added this code:
firstNameTextField.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
trigger.triggerCommit();
}
});
When I hit the enter button with degbugging on, the actionListener fires just like it would if I hit Commit Buffer Button, but nothing is committed when I display the values. I am very puzzled by this. There has to be a way to get JGoodies working with keyboard input. I shouldn't have to click out of the JTextField for the text to get to the Value Model.
Upvotes: 1
Views: 398
Reputation: 10333
Sorry about this question, I didn't explain it very clearly. Here is the answer though:
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 :)
Upvotes: 1
Reputation: 324207
I have a keyListener on the JTextField that commits data to the model when the "enter" key is pushed.
Probably not related to your problem, but you should be using an ActionListener to handle the Enter key, not a KeyListener.
Upvotes: 1