사용자 정의 TableCell 셀 팩토러스를 만들었습니다. Decimal 입력 (숫자 & 한 점 (.) 만 허용)을 원합니다. 아래 replaceText & replaceSelection에 대한 코드가 있지만 아무것도 입력 할 수 없습니다.십진수 만 입력 한 JavaFX 사용자 정의 CellFactory
@Override
public void replaceText(int start, int end, String text) {
if (text.matches("/^\\d*\\.?\\d*$/")) {
super.replaceText(start, end, text);
}
}
@Override
public void replaceSelection(String text) {
if (text.matches("/\\d*\\.?\\d*$/")) {
super.replaceSelection(text);
}
}
};
아직 작동하지 않습니다. 그게 내가 아무것도 입력하지 못하게 해. –
메서드에 전달되는 텍스트 대신 정규식에 대한 대체 결과를 테스트하지 않아도됩니까? String과 같은 것 newText = getText(). substring (start) + text + getText.substring (end); if (newText.matches ("...")) {super.replace (start, end, text);}' –