• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Rendering dates from long values in JTable

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to render or display dates from the long values stored in my table model. What is the best way to do this. I've found other info on this but it assumed you had Date objects in the tablemodel.

Sean
 
Data Virtue
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used this code to set my renderer.

return new DefaultTableModel(data,headers){
public Class getColumnClass(int column) { //this code makes sure the proper renderer is used
return DV.idObject(this.getValueAt(0,column));
}
};

In my idObject method I returned Date.class when I ran into a Long column.

Next question, What is the best way to change the date format of the default renderer?

Sean
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Data Virtue", you have previously been warned on multiple occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional, and this is your final warning. Adjust your display name to comply with the required standards prior to your next post.

Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Failure to comply will result in the removal of your account.

bear
JavaRanch Sheriff
[ November 10, 2008: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Data Virtue:
Next question, What is the best way to change the date format of the default renderer?


Use a custom date format.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could set the TableCellRenderer for that column to be a custom renderer in which you'd need to override:

public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column){
DateFormat df = new SimpleDateFormat("yyyyMMdd");
this.setText(df.parse(new Date((Long)value)));
return this;
}
[ November 15, 2008: Message edited by: J. Noah ]
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic