• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSpinner Percentage editor as JTabel CellEditor

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Do Re Mi Fa So La Tiny Ad
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic