Search code examples
javaswingjtextfield

How do I put a comma on a textfield if what is used to initialize the textfield is a double?


How do I put a comma on a textfield if what is used to initialize the textfield is a double?

So, the declared double variable is equal to, lets say, 10,000. I use it to put a "10,000" on a textfield. So, this is what I want to happen...

This kind of result: This kind of result

However, what I get is something like this:

What I get

How do I make the output in the textfield into "24,508.0" (with a comma) instead of just "24508.0"? I was thinking, maybe, I could turn it into an array. But how?


Solution

  • You have to use a formatted text field. Check out this link for more information. I would also like to note that a Boolean is either true or false. Not 10,000.