Search code examples
javaswingfloating-pointjtablelocale

JTable with float column with correct locale


I use a JTable to display a search result of articles from a database and i have a couple of columns that are float for the price of the article.

Some of the columns are editable so that you can adjust the price before you save the articlerow to offerlines.

But as you edit the price of an article you have to enter the price as 200.30 but in my current locale that is sweden, we use 200,30.

How do I accomplish so that i dont get an error while trying to write with a comma instead of dot?

This is how it looks today, with "262.0" and that is what is needed. This is current how you have to enter data

But here is how i want it to work, users shouldnt have to think about that they use dot as decimal separator. So I want to be able to enter comma. "262,0". But i get a red error rekt as i try to enter this and I dont know how to come around this This is how i want it to be, but as you see it turns red when i try to enter with a comma


Solution

  • You probably need to implement a custom cell editor. Perhaps JTable cell editor number format will help.