• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextField - display dd/mm/yyyy

 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would your requirement differ to just adding a JLabel next to the textfield.
(there's also setToolTipText())
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would something like this work OK?

 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by the way does the above sound like a bad design choice?
[ June 18, 2006: Message edited by: Lynette Dawson ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic