raj5c1
9 years agoOccasional Contributor
getting display format of the data field in java swing table
I am trying to get the value from Date field of one of the columns in Jtable object. When i get the value i am using toString on it (OleValue is not working). But toString converting the date to default format( Mon Nov 03 08:00:42 CDT 2016) instead of the displayed format(eg 11/03/2016). I tried to use the few native methods like cellRender object of that column but none of them have any value.
Here is how iam getting the value
grid.getValueAt(0, 1).toString
Is there any way that i can get displayed text form Date object.
Hi raj5c1,
Try this function:
// Returns the displayed value in the specified JTable cell
// Parameters:
// table - a JTable object
// row, column - integer indexes of the row and column
function getRenderedValue(table, row, column) { var value = table.getValueAt(row, column); var renderer = table.getCellRenderer(row, column).getTableCellRendererComponent(table, value, false, false, row, column); if (aqObject.IsSupported(renderer, "getText")) { value = renderer.getText(); } return value; }It is based on the code found on GitHub:
Extract table cell value from cell renderer rather than model