• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSpinner Percentage editor as JTabel CellEditor  RSS feed

 
Kim Mirtens
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brian Cole
Author
Ranch Hand
Posts: 947
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kim Mirtens:
I want use a JSpinner to edit percentage values in my JTable.

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.


They don't make it easy to get at the JSpinner internals, do they.

Here's some code that I came up with that seems to work. Let me know what you think.

[ April 15, 2008: Message edited by: Brian Cole ]
 
Kim Mirtens
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!