Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

java - Get jDateChooser date to jLabel

This is my infernal problem. nowadays i'm trying to create my project according to my Degree. I already have added jcalender to my project in netbeans, and i already added jDateChooser to my jFrame. my problem is, when i chooseing a date from jDateChooser how will display this date on a jLabel. i tried to using jLabel1.setText(jDateChooser1); but in this case error will occur. http://imgur.com/nMa9JMw

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First, you need to get the date from the component, something like...

Date date = jDateChooser1.getDate();

Next you need to format that Date value to a String

String strDate = DateFormat.getDateInstance().format(date);

Finally, you need to set that value as the text for the lable...

jLabel1.setText(strDate);

If you have particular formatting requirements, you may need to look at SimpleDateFormat


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.6k users

...