Updating jtable data

Posted by / 10-May-2019 18:49

Updating jtable data

It does make sense when the user enters all the data.

I was hoping there would be a way not much harder than what is done for the Cell Renderer to set the format for the Cell Editor.

So I think it looks better to display 1.67, especially when the program is writing into the table, but when it comes time for the calculations, I can't afford to lose the precision. So let's suppose you got your wish and the cell editor showed "1.67" to the user.

Not sure if the value actually changes if the user leaves the cell without hitting enter. I will answer this in 2 parts: First, the solution to your problem: the following editor works for most cases for you: 1) retains the validation part of having a red border for invalid values 2) when the user clicks in the cell to edit, sets the caret position to 0 so that the user can see the beginning of the value (you can't select all as well as have the position as 0 - I don't know if textfield allows editing also from right).

3) Also, display the value in the textfield as you had wanted to - I have not tested this well, so, I have commented this out in line no.11 - I am not sure how this works out for null or empty values - nf is the Number Format you used...

If I click on that cell to change 1.67 to something else, it displays as 1.6666666666666666666, which looks bad and is a bit hard to select and change.

How do I get just 1.67 to remain displayed when the user clicks in the cell to change the value?

updating jtable data-22updating jtable data-10updating jtable data-75

All I could find looked like I would have to reimplement all the behaviors the default cell editor provides and make my own complete cell editor starting with an abstract cell editor.