0
爲什麼以下CellRenderer
不會格式化時間戳?而不是HH:mm
我收到一些東西,例如07:00.000.00
單元格渲染器不會格式化時間戳
DefaultTableCellRenderer cellRenderer = new DefaultTableCellRenderer()
{
public Component getTableCellRendererComponent(JTable table, Object value, boolean
isSelected, boolean hasFocus, int row, int column)
{
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (value instanceof LocalDateTime)
{
DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm");
String strTime = formatter.print((LocalDateTime)value);
this.setText(strTime);
}
return this;
}
};
也許'value'不是'LocalDateTime'。然後'super.getTableCellRendererComponent(...)'將被單獨調用。你應該檢查類型。 –
@Meno Hochschild:是的,它是LocalTime的實例。謝謝。 –
爲了更快獲得更好的幫助,請發佈[MCTaRE](http://stackoverflow.com/help/mcve)(最小完整測試和可讀示例)。 –