I cannot get your error when using this in a simple JavaFX application. Here is the code I used to test your implementation. My test input "AA20552055T" matches the regular expression - the text field is cleared.
Can you compare with your solution:
public class JavaFXApplication1 extends Application { @Override public void start(Stage stage) throws Exception { Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml")); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } }
Controller class with your logic:
public class FXMLDocumentController implements Initializable { @FXML private TextField textfield; @Override public void initialize(URL url, ResourceBundle rb) { textfield.textProperty().addListener( (observable, oldValue, newValue) -> { handleInput(newValue); }); } private void handleInput(String s) { s = s.toUpperCase(); Matcher matcher = Pattern .compile( "^[AZ]{2}(20|21|22|23|[0-1]\\d)[0-5]\\d(20|21|22|23|[0-1]\\d)[0-5]\\d(T\\s|C\\s|TC|CT|\\s\\s)$") .matcher(s); if (matcher.find()) { // do something // then clear the textfield textfield.clear(); } else { // do something else } } }
FXML File:
<?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication1.FXMLDocumentController"> <children> <TextField layoutX="126" layoutY="150" fx:id="textfield" /> </children> </AnchorPane>
As for the comment, I installed JDK 1.8.0_45 (up to 1.8.0_20) Working with Windows 7 x64 Again, no errors.
Here Netbeans jar is automatically created - I tested it from CMD. The work is also wonderful. Can you check if the jar file from CMD is working on your computer?
For debugging, this is a method in which the exception data is specified by the change parameter. change has start and end .
private void updateContent(TextFormatter.Change change, boolean forceNewUndoRecord) { final boolean nonEmptySelection = getSelection().getLength() > 0; String oldText = getText(change.start, change.end);
The start and end values โโthen throw an exception in getText(...) :
public String getText(int start, int end) { if (start > end) { throw new IllegalArgumentException("The start must be <= the end"); } if (start < 0 || end > getLength()) { throw new IndexOutOfBoundsException(); } return getContent().get(start, end); }