Search code examples
javaswingdocumentjtextfieldjformattedtextfield

how to manipulate jtextfield return type?


I have a jtext field

when user type a number like

123456789,10

it will automatic set in jtextfield

123,456,789.10

then if user click a button it will

System.out.print( the_same_number );

that will result

123456789.10

  • how to do this?
  • how to make jtextfield only accept input number and dot (.) and coma (,)?

(should i use formatted field in this case?)

thanks..


Solution

  • You will want to use a DocumentFilter to filter the input coming into the text field.

    Check out MDP's Examples which actually has an example of the question you are asking