Zero-padding spinner in Java

How to add zero addition to JSpinner?
Since the spinner creates itself JFormattedTextField, I cannot just pass this format to the JFormattedTextField constructor.
There is no way to set the formatting in the existing JFormattedTextField?

What I want: value = 37, editor = "0037"

UPDATE:
I tried this as suggested:

JSpinner mySpinner = new JSpinner();  
mySpinner.setEditor(  
    new JSpinner.NumberEditor(mySpinner, "####"));  

and the result will not change at all to the presentation of the counter data. This seems like a reasonable decision; Has anyone tried this successfully, so I can be sure that it is just peeling something in my own application?

+3
source share
2 answers

, :

// minimum of four digits
mySpinner.setEditor(new JSpinner.NumberEditor(mySpinner, "0000"));

"0000" DecimalFormat, , ; "####" , .

DecimalFormat API .

+5

javadocs, JSpinner setEditor (JComponent). , JFormattedTextField .

0

Source: https://habr.com/ru/post/1710099/


All Articles