TextField Document model

Will Hoover java.whoover at gmail.com
Wed Oct 17 11:13:18 PDT 2012


Have you tried:

final TextField tf = new TextField() {
	final String restictTo = "[A-Z\\s]*";
	@Override
	public void replaceText(int start, int end, String text) {
		if (matchTest(text)) {
			super.replaceText(start, end, text);
		}
	}
	@Override
	public void replaceSelection(String text) {
		if (matchTest(text)) {
			super.replaceSelection(text);
		}
	}
	private boolean matchTest(String text) {
		return text.isEmpty() || text.matches(restictTo);
	}
};

-----Original Message-----
From: openjfx-dev-bounces at openjdk.java.net
[mailto:openjfx-dev-bounces at openjdk.java.net] On Behalf Of Mark Claassen
Sent: Wednesday, October 17, 2012 1:08 PM
To: openjfx-dev at openjdk.java.net
Subject: TextField Document model

JTextComponents (like JTextField) has a javax.swing.text.Document model that
made it pretty easy to create a text field that only allowed a certain
number of characters in it.  Similarly, it was also easy to make a Document
model that took all input, but forced characters to upper case.

@Override
public void insertString(int offs, String str, AttributeSet a) throws
BadLocationException {
     <Do stuff>
}

What is there going to be in JavaFX to accomplish the same goals?

Mark



More information about the openjfx-dev mailing list