0

I have used DatePickerCellEditor for a cell in Jtable. When I select a date from the popup calender, the date with dow mon dd hh:mm:ss zzz yyyy format is displayed. I want to change it to date format (yyyy-MMM-dd).
I did try doing by:

DateFormat formatter ;

formatter = new SimpleDateFormat("yyyy-MMM-dd");

DatePickerCellEditor datePicker = new DatePickerCellEditor(formatter);

TableColumn po_date = tableModel.getColumnModel().getColumn(1);

po_date.setCellEditor(datePicker);

But it didn't work. Can anyone help me with this one?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
sam
  • 1
  • 1
  • 1
    "*But it didn't work.*" > Can you explain what didn't work? Do you see an error? Does it display the wrong value? – Duncan Jones Feb 11 '13 at 09:47
  • 4
    which one from `(J)DatePickers`, for better help sooner post an [SSCCE](http://sscce.org/), short, runnable, compilable, just about `JFrame` with `JTable` (one row & cell) with your code for `(J)DatePickers` as `Renderer` & `Editor` – mKorbel Feb 11 '13 at 09:51
  • There was no error but the formatting which i did showed no effect. – sam Feb 11 '13 at 09:52
  • `JCalandar` has no such class. Do you mean `org.jdesktop.swingx.table.DatePickerCellEditor`? – trashgod Feb 11 '13 at 23:49

2 Answers2

1

Your code needs a small change ,

Instead of

formatter = new SimpleDateFormat("yyyy-MMM-dd");

use:

formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);

Hope this works for you.

linski
  • 5,046
  • 3
  • 22
  • 35
CleanX
  • 1,158
  • 3
  • 17
  • 25
-1

is that column editable? you should allow that column to be editable overriding method isCellEditable of your TableModel class

Josue Martinez
  • 436
  • 5
  • 14