Two Laptop Bag*
The moose likes Swing / AWT / SWT and the fly likes Date in a JTable and a JTextField in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Date in a JTable and a JTextField in "DD/MM/YYYY" format" Watch "Date in a JTable and a JTextField in "DD/MM/YYYY" format" New topic
Author

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

tina sow
Greenhorn

Joined: Sep 23, 2002
Posts: 13
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

Joined: Sep 23, 2002
Posts: 13
I forget to say that i'm using visualage for java4
(jdk1.3)
thanks
Tina
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Check out the SimpleDateFormat API. That will show you how to format the date however you want to.
San Su
Ranch Hand

Joined: Jul 06, 2001
Posts: 313
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

Joined: Jul 06, 2001
Posts: 313
Is there any tag for code??
Added later : Found it..
[ October 25, 2002: Message edited by: Sankar Subbiah ]
tina sow
Greenhorn

Joined: Sep 23, 2002
Posts: 13
Thanks a lot.
The example works fine.
Tina
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Date in a JTable and a JTextField in "DD/MM/YYYY" format
 
Similar Threads
JTable date edit problem
java.text.SimpleDateFormat
java.text.ParseException
Null Value in JTable
Trouble with JTable sorting dates.