On Tue, 7 Dec 2021 05:20:42 GMT, Tejesh R <[email protected]> wrote:

>> I agree. Simply deleting this line solves nothing. The example needs to be 
>> reviewed and the text needs to say something correct and useful.
>
> Yeah, I've checked with `valueToString` method, its working fine. I'll 
> replace `getDisplayValue` with `valueToString`? ValueToString takes one 
> parameter which is of Object type. It return the formated value.
> Sample Code:
>         MaskFormatter formatter = new MaskFormatter("###-##");
>         formatter.setPlaceholderCharacter('*');
>         System.out.println(formatter.valueToString("87"));
> 
> Output:
> 87*-**

Yes, this will make the example correct.

This sample code demonstrates what is discussed in the docs:

MaskFormatter formatter = new MaskFormatter("###-####");
formatter.setPlaceholderCharacter('_');
System.out.println(formatter.valueToString("123"));

formatter = new MaskFormatter("###-####");
formatter.setPlaceholderCharacter('*');
formatter.setPlaceholder("555-1212");
System.out.println(formatter.valueToString("123"));

and produces the output:

123-____
123-1212

which perfectly aligns with the documentation.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6556

Reply via email to