This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have a formatting challenge that I'm trying to rectify. I'm working with a JTable and a JSpinner class. I got the working code sample from http://forums.devshed.com/java-help-9/datepicker-inside-a-jtable-536152.html. I decided I wanted to use it, but it needs some formatting issues worked out. Basically I'm trying to ensure that a Date field in JTable always displays via format "MM/dd/yyyy". I'm working with two classes which you can see below. I tried setting up a couple more methods that perform some formatting for me, but it meant changing the Date type to a String type, and well, it just messed things up. As you look at the lines of code that have been commented out, you can probably see what I was trying to do.
As it stands now, when the JTable first loads the data, it is formatted in the cell using some ugly default Date format. I want it to display always in the format "MM/dd/yyyy". When I click on the date cell the JSpinner certainly does display in the proper format dictated in the constructor of DateCellEditor. Then after editing and the cell loses focus, that ugly default date format shows up again. Could someone please show me what it is I need to do to retain the format I want for this date cell? I'm a bit lost on this one.