• 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 a JTable and a JTextField in "DD/MM/YYYY" format

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I'am learning java and i would like to know how to write code for a jtable column and also for a Jtextfield in order to have this format:
"DD/MM/YYYY".
If you have code examples , it would be great.
Thanks
Tina
 
tina sow
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forget to say that i'm using visualage for java4
(jdk1.3)
thanks
Tina
 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the SimpleDateFormat API. That will show you how to format the date however you want to.
 
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In JTable, there are two components used in every column.
1. Renderer :

Renderer is responsible for rendering the data and display it in the table. Default renderer extends from JLabel, You can write your own custom renderer to format data to whatever format you want it to be displayed. But, the underlying data is not changed.
2. Editor:
Editors are kind of wrapper around the actual editing component. Components can be anything extends from JComponent. Default editor is JTextField. You can create your own custom editor for your editing needs. If you edit the value in a cell and move focus to next cell/row, the value will be updated in the Model by the Editor.
(I am just telling this because you said you are new. If you already know it, please ignore it)
Ok.. here is the code for CustomDateCellRenderer

CustomDateEditor is little bit hard. If you like to have a it as a mask field, you have to write lots of code.. I can give you a skeleton only.

[ October 25, 2002: Message edited by: Sankar Subbiah ]
 
San Su
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any tag for code??
Added later : Found it..
[ October 25, 2002: Message edited by: Sankar Subbiah ]
 
tina sow
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot.
The example works fine.
Tina
 
reply
    Bookmark Topic Watch Topic
  • New Topic