【问题标题】:Jdatepicker not working in jtableJdatepicker 在 jtable 中不起作用
【发布时间】:2013-02-11 09:42:09
【问题描述】:

我已将DatePickerCellEditor 用于Jtable 中的单元格。当我从弹出日历中选择日期时,会显示dow mon dd hh:mm:ss zzz yyyy 格式的日期。我想将其更改为日期格式(yyyy-MMM-dd)。
我确实尝试过:

DateFormat formatter ;

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

DatePickerCellEditor datePicker = new DatePickerCellEditor(formatter);

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

po_date.setCellEditor(datePicker);

但它没有用。谁能帮我解决这个问题?

【问题讨论】:

  • "但它不起作用。" > 你能解释什么不起作用吗?你看到错误了吗?它是否显示错误的值?
  • 哪一个来自(J)DatePickers,为了更好的帮助,请尽快发布SSCCE,简短,可运行,可编译,大约JFrameJTable(一行和单元格)与您的代码(J)DatePickers as Renderer & Editor
  • 没有错误,但我所做的格式化没有效果。
  • JCalandar 没有此类。你的意思是org.jdesktop.swingx.table.DatePickerCellEditor

标签: java swing jtable simpledateformat jcalendar


【解决方案1】:

您的代码需要稍作改动,

代替

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

使用:

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

希望这对你有用。

【讨论】:

    【解决方案2】:

    该列是否可编辑?您应该允许该列是可编辑的,覆盖 TableModel 类的 isCellEditable 方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-23
      • 1970-01-01
      相关资源
      最近更新 更多