I'm trying to call method after changing text of JTextField.
textField.getDocument().addDocumentListener(new DocumentListener()
{
public void changedUpdate(DocumentEvent arg0)
{
System.out.println("IT WORKS");
panel.setPrice(panel.countTotalPrice(TabPanel.this));
}
public void insertUpdate(DocumentEvent arg0)
{
}
public void removeUpdate(DocumentEvent arg0)
{
}
});
When I call this method at another ActionListener, it works ok. But when I change text in text field, nothing happens. Even println. Any suggestions?
The problem solved. changedUpdated method called only when other atributes (font, size, but not text) changed. To call method after every change of text, I should put the call into insertUpdate and removeUpdate methods. This way:
textField.getDocument().addDocumentListener(new DocumentListener()
{
public void changedUpdate(DocumentEvent arg0)
{
}
public void insertUpdate(DocumentEvent arg0)
{
System.out.println("IT WORKS");
panel.setPrice(panel.countTotalPrice(TabPanel.this));
}
public void removeUpdate(DocumentEvent arg0)
{
System.out.println("IT WORKS");
panel.setPrice(panel.countTotalPrice(TabPanel.this));
}
});
Try using an ActionListener
:
textField.addActionListener(this);
...
public void actionPerformed(ActionEvent evt) {
String s = textField.getText();
System.out.println(s);
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With