aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTextField - display dd/mm/yyyy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField - display dd/mm/yyyy" Watch "JTextField - display dd/mm/yyyy" New topic
Author

JTextField - display dd/mm/yyyy

Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
Hi there, I would like to extend swing's JTextField in my application and modify it's paintComponent() function so that it displays the label "dd/mm/yyyy" next to the text field. However I dont have a clue as to how to do this (never played with paintComponent() or Graphics2D class before). Can someone help me out?


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
How would your requirement differ to just adding a JLabel next to the textfield.
(there's also setToolTipText())
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
well, i will be displaying 1000s of date fields throughout my application. i dont want to put a label that displays "dd/mm/yyyy" in 1000 places. Thats why I want to extend JTextField and create a custom component.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
would something like this work OK?

Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
not really. i want to extend the JTextField (not JPanel) for my date fields.

I will be adding few more utility functions (and some custom constructors) to my JDateField class (for example - prepopulate it with current date / start of financial year / add custom validations on lostFocus() etc... )

in future, i will be modifying my jdatefield class to display a small button next to it (when clicked, the button opens a calender control)
[ June 18, 2006: Message edited by: Lynette Dawson ]
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
by the way does the above sound like a bad design choice?
[ June 18, 2006: Message edited by: Lynette Dawson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextField - display dd/mm/yyyy