Masking javafx textfield input

user2570 :

I am using a javafx textfield. I need to enter numbers along with decimals that should match the format ###.###.###.###
where the decimals should not be editable at all, and the numbers can be any digit; no other input is allowed. Not all digit placeholders need to be filled , e.g. it could be 1.2 or 2.22.1 or even 1.222.222.0

I have tried using Pattern matching with regex to validate the altered text, but that's all it does; it validates input, it does not make the decimal field a non editable field, and tooltip is not an option. I am not sure of what else to try.

I am trying to find a way so that even while users type they can see what the expected input is e.g. 1##.###.###.###. While they are entering numbers, they do not enter the decimal as it is 'fixed' in the text field, or atleast appears to be. If continuous number input is received, the typed numbers skips the decimal when it encounters it and automatically goes to the next field. e.g. user input ="1234" output="123.4##.###.###"

another suggestion would be to automatically advance the cursor when a decimal is received e.g. user input = "1.23.4" output = "001.023.004.###"

Any and all suggestions are welcome, and just for clarification the "#" is part of the textfield 'hint' and not part of the actual text.

user2570 :

In the end, used UnaryOperator with regex for input control and StringCoversion to post process text as used here How to force a double input in a TextField in JavaFX? in case anyone else runs into this problem.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=155348&siteId=1