My problem is this:
I have JTable
with several populated columns with data pulled from my database. Some of these columns are time values, for example, 0834 is pulled from the database and I would like it to be displayed 08:34
I'm not able to implement library resources SimpleDateFormat
. I followed some tutorials from American StackOverflow and my output is always the same: 21:00
, regardless of the value the bank sends.
My code in class TimestampCellRenderer
is
import java.text.SimpleDateFormat;
import javax.swing.table.DefaultTableCellRenderer;
public class TimestampCellRenderer extends DefaultTableCellRenderer {
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
public TimestampCellRenderer() {
super();
}
public void setValue(Object value) {
setText((value == null) ? "" : formatter.format(value));
}
}
And in the GUI class I have the following line:
tableResultados.getColumnModel().getColumn(4).setCellRenderer(new TimestampCellRenderer());