0

I am trying to create a TextArea in JavaFX which only accepts integer values? Can anyone give me advice as to how to implement this?

2
  • 1
    See linked question - should work similarly for TextArea as does for TextField. Commented Apr 7, 2017 at 15:05
  • 1
    Presumably in a TextArea you would want to allow newlines at least, and possibly whitespace in general, so you would need to modify the regex in that answer. Commented Apr 7, 2017 at 15:18

1 Answer 1

1

Use a TextFormatter:

TextArea textArea = new TextArea(); // allow digits and whitespace: Pattern allowedText = Pattern.compile("[0-9\\s]*"); TextFormatter formatter = new TextFormatter((TextFormatter.Change c) -> { if (allowedText.matcher(c.getText()).matches()) { return c ; } else { return null ; } }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.