"well, this is only a simple program that design to handle yyyyMMdd at the moment. I want to take one step at a time and to understand how to program and format the date"
As for the format, you shouldn't be using a
DecimalFormat
. Instead use aDateFormat
. A commonly used subclass isSimpleDateFormat
As for your current implementation of
DefautTableCellRenderer
, you are missing a key component, which is the overriding ofgetTableCellRendererComponent
. You can see How to use Renders for a proper way. Also there are may questions you can look at.As for your overriding of
getColumnClass()
, the column class shoun't be the renderer component. You couln't instead make the column classDate
and have the default renderer forDate
do the rendering for you. You can see more at Using Renderers. If you don't want to it beDate
and keep it asString
, then the renderer should handle the re-rendering to the correct format.As for other options to handle the entering of invalid input:
- You can look into using an
InputVerifier
for the editing component for the cell. You can see an example here and also many questions. - You may even want to look into using some kind of date picker component for the editor of the cell. You can see many related questions here
- You may want to use a
JSpinner
for the editor. See many questions
- You can look into using an