2017-04-07 3 views
0

JavaFX에서 정수 값만 허용하는 TextArea를 만들려고합니까? 누구든지이 구현하는 방법에 대한 조언을 줄 수 있습니까?정수 만 입력 할 수 있도록 JavaFX에서 TextArea를 어떻게 설정할 수 있습니까?

+1

연결된 질문을 참조 - TextField''의 경우와 같이 TextArea''에 대한 유사하게 작동합니다. – Itai

+1

아마도'TextArea'에서 최소한 개개의 공백이나 공백이 허용되기를 원할 것입니다. 그래서 그 대답에서 정규 표현식을 수정해야 할 것입니다. –

답변

1

사용하십시오 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 ; 
    } 
}); 
+0

대단히 감사합니다! – onagh