获取jDateChooser日期到jLabel [英] Get jDateChooser date to jLabel

查看:154
本文介绍了获取jDateChooser日期到jLabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的恶劣问题。现在我正在尝试根据我的学位创建我的项目。我已经在netbeans中为我的项目添加了 jcalender ,我已经将jDateChooser添加到了我的jFrame中。我的问题是,当我从 jDateChooser 中选择日期时,如何在jLabel上显示此日期。我试图使用 jLabel1.setText(jDateChooser1); 但在这种情况下会发生错误。
http://imgur.com/nMa9JMw

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

推荐答案

首先,您需要从组件中获取日期,例如......

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

Date date = jDateChooser1.getDate();

接下来你需要格式化 Date 值到字符串

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);

如果您有特定的格式要求,您可能需要查看 SimpleDateFormat

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

这篇关于获取jDateChooser日期到jLabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆