Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date in a JTable and a JTextField in "DD/MM/YYYY" format

 
tina sow
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I forget to say that i'm using visualage for java4
(jdk1.3)
thanks
Tina
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the SimpleDateFormat API. That will show you how to format the date however you want to.
 
San Su
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Thanks a lot.
The example works fine.
Tina
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic