• 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

Hiding the actual data values in the DataModel when displaying with JTable

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application that keys off the values in a column in my table. A new requirement is that the GUI have an option to change the units in that column. One thought I had to satisfy this new requirement was to modify the cell editor and cell renderer. So if I did a getValue on the table, I'd always get the same value, but the user would see values scaled in the units they requested. The code is below. It's not my only choice. I could also modify getValue and setValue to do the conversion. Or I could modify all the classes and methods that currently expect specific units. I like the idea of handling the conversion early, but I am wondering if anyone has comments on the 'best practices' way of handling this. And also, if my code is not right, suggestions to improve it.

If you run it, just type a number in the cell. Set Scale doubles the scale every time you press it, while Press Here gives the value in the model.

 
reply
    Bookmark Topic Watch Topic
  • New Topic