I want use a JSpinner to edit percentage values in my JTable. I wrote the following code:
The problem is when users hit enter. When they manually typed the "%" sign and hit enter twice it works. When they didn't enter the "%" sign it doesn't work. I tried a keylistener on both the editor and the spinner and also an inputMap, but none of these things seem to be noticing events. I had the same problem when the user exited the cell, which I tried to fix in the stopCellEditing() by adding a "%" sign. This does work but only in the case where the user has entered less then 2 fraction digits (otherwise it doesn't follow the pattern "0.00%"). How can I get around these problems? I really want the users to be able to commit when they hit enter.
First of all I want to thank you for all your trouble. This code works better then mine. Your code always commits when enter/return is pressed twice (whith or without percentage sign). When the user only presses once the numberformat is corrected; when he then presses again the value is actually commited to the table. Do you have any ideas on how to get the value commited to the table after a single keypress?