You must have something looking at the focus or you think it is firing and it is not I took your code and made a complete example and it does not have the problem you describe JFrame frame = new JFrame(); final JTextField numPlotRowsJTextField = new JTextField(3); numPlotRowsJTextField.getDocument(). AddDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent e) { } @Override public void insertUpdate(DocumentEvent e) { numPlotRowsJTextField. SetBackground(Color.
Cyan); } @Override public void removeUpdate(DocumentEvent e) { } }); frame. SetDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); frame.
SetSize(100, 100); frame.getContentPane(). SetLayout(new FlowLayout()); frame.getContentPane(). Add(new JTextField(2)); frame.getContentPane().
Add(numPlotRowsJTextField); frame. SetVisible(true).
You must have something looking at the focus or you think it is firing and it is not. I took your code and made a complete example and it does not have the problem you describe. JFrame frame = new JFrame(); final JTextField numPlotRowsJTextField = new JTextField(3); numPlotRowsJTextField.getDocument().
AddDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent e) { } @Override public void insertUpdate(DocumentEvent e) { numPlotRowsJTextField. SetBackground(Color. Cyan); } @Override public void removeUpdate(DocumentEvent e) { } }); frame.
SetDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); frame. SetSize(100, 100); frame.getContentPane().
SetLayout(new FlowLayout()); frame.getContentPane(). Add(new JTextField(2)); frame.getContentPane(). Add(numPlotRowsJTextField); frame.
SetVisible(true).
I think JGoodies Binding is messing me up somehow. It must be causing the DocumentListener to fire insertUpdate even when I just change focus. It probably has to do with the face that I am using JGoodies buffered input and a trigger which allows me to reset my input easily.
Any JGoodies binding experts out there? – Bluebomber357 Jan 6 at 15:49.
Does it actually contain a string that has changed. Or is it just an event with a 0 length string. If it is the latter then maybe you can just ignore that case.
I figured it out. It 100% had to do with JGoodies Binding. This code works: ValueModel valueModelNumberPlotRowsJTextField = adapter.
GetBufferedModel("numberOfPlotRows"); valueModelNumberPlotRowsJTextField. AddValueChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { numPlotRowsJTextField. SetBackground(Color.
Cyan); } }); numPlotRowsJTextField = BasicComponentFactory. CreateIntegerField(valueModelNumberPlotRowsJTextField); Since I am using JGoodies Binding, I have a ValueModel backing my JTextField. The listener has to be set there and not on the JTextField.
I have a JTextField with a documentListener on it. I want to change the background color when I add or remove characters to this textfield. I should be using a document listener correct?
It works, but it also fires when I gain and lose focus on this JTextfield, which is undesired. I do not add a focus listener on this JTextField. Here is my code, any suggestions on how I can fix my problem?
Also note that I am using JGoodies Binding which I am starting to believe is the root of this problem. Swing w/o JGoodies shouldn't be firing off document listener events by changing focus...
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.