• 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

Date in JTable

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there is a way to restrict a jtable column to accept only date as input.
and format it to a specific format?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by paritosh pandey:
Is there is a way to restrict a jtable column to accept only date as input.
and format it to a specific format?



The JTable pulls out data from the table model. JTable is just the view. It is bad usability to allow the user to edit in the table directly. Usually you present a dialog to the user, which he can use to edit single/multiple records. You can use a JFormatted text field or something similar to restrict and control the user input.

You can create customized renderers to display the date in the format of your choice or modify the getValueAt() method of your table model to return the correctly formatted string.
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Maneesh Godbole:

...It is bad usability to allow the user to edit in the table directly...



I beg to differ - I'd say it's good usability to allow the user to edit in the table directly - people like Excel, after all, I think they'd get annoyed if you had to do any editing in a dialogue.

It does make our jobs as developers harder, but I think it is more user-friendly - no?
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Payne:


I beg to differ - I'd say it's good usability to allow the user to edit in the table directly - people like Excel, after all, I think they'd get annoyed if you had to do any editing in a dialogue.



I worked in a company previously where a PhD. Usability Expert was in charge of designing the UI. Like you I was of the same opinion. When I discussed this with him, his explanation was:
"Whenever the user is going to change anything, which might possibly affect different things, it is always advisable to present the user with an edit dialog. This is a visual clue to the user, that he is doing something which is not in line with the generic work flow. Also, the table cells might not be displaying all the information. So a dialog with all the information properly presented is always preferred."

Of course usability is extremly subjective, and I do not intend at all to fire of any debate. Once upon a time I had come accross a usability article by Sun. It would be interesting to take a look at their view on this. I will try to hunt it out and post the link.
 
Mark Newton
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see your point, Maneesh, and was really only being awkward I guess I'd say that this is an example of where academic theory differs from what people want (or think they want).

It would definitely be 'better', in Excel to show all the facts about the cell you're editing - for example, whether the value that you're seeing now is a constant, or the result of some other formula, in which case you probably don't want to just delete that value. BUT, try making an application that works like that - people will ask why it can't work the same as Excel...

Sorry, paritosh, I've hijacked your thread completely unnecessarily.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Originally posted by Maneesh Godbole:

You can create customized renderers to display the date in the format of your choice or modify the getValueAt() method of your table model to return the correctly formatted string.



Because I'm using sorter in my table, so by format the date in getValueAt method, my sortable can't be sorted properly anymore

How can I format the date without affect sortable thing or wihtout convert the date to String ??
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hafiz Yusof:


How can I format the date without affect sortable thing or wihtout convert the date to String ??



Use a renderer. Let the getValueAt return the Date object so that the sorting is not affected.
 
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
These are the default renderer and editor used by JTable for Date.class:

You can recreate these classes but then just the way you want. The renderer is easy - just use your own (Simple)DateFormat. The editor can be customized a bit more though:

[ August 05, 2008: Message edited by: Rob Prime ]
 
Hafiz Yusof
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob and Maneesh.

Now by using Rob's approach, I can format the date and do sortable things happily ever after
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic