I am maintaining what is now pretty old code. One aspect is there are a lot of tables that have columns whose values change depending on the setting of a variable for units (e.g. switching from inches to feet to meters). The underlying model maintains the value in the default units, but the view shows the user specified units. This is very handy, as all the calculations done can assume default units that are returned from the underlying table model.
Now of course, the same functionality is being requested for some JTextFields (rather than tables). I was hoping to use the same sort of design, but I am not seeing a way to set the renderer (or cell editor) for a plain JTextField.
Here is an example of what is done for the table column.
I was hoping to set a renderer for the JTextField.
Should I just have a block of of code when I open the dialog to set units using setText() to put in the converted value and then when I close the dialog read the text and convert it back to the default units? In other words, there is no reason to get too fancy?
I suppose I could extend JTextField and override setText and getText.
Is there a better way to handle this sort of case (maintain something in default units and displaying it in some alternate units) for JTextField?