Using DocumentFilter.FilterBypass

For instance, here’s an SSCCE with a DocumentFilter which prevents the user from typing numbers into the document but allows the Swing Timer to do so. import java.awt.event.*; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.text.*; public class DocFilterPanel extends JPanel { private JTextArea textArea = new JTextArea(12, 50); private MyDocFilter myDocFilter = new MyDocFilter(); public DocFilterPanel() … Read more

How to use TextAction

From Java Swing 2nd Edition: All text components share a set of default Actions. Each of these Actions are instances of TextAction by default. JTextComponent provides a private static EditorKit which consists of a set of four pre-built TextActions shared by all text components through the use of a default Keymap instance. JTextComponent maintains a … Read more

java change the document in DocumentListener

DocumentListener is really only good for notification of changes and should never be used to modify a text field/document. Instead, use a DocumentFilter Check here for examples FYI The root course of your problem is that the DocumentListener is notified WHILE the document is been updated. Attempts to modify the document (apart from risking a … Read more