Question

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

Was it helpful?

Solution

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

OTHER TIPS

String date  = ((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText();
jLabel1.setText(date);

Try this,

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String date = sdf.format(jDateChooser1.getSelectedDate().getTime());
jLabel1.setText(date);

import this file>>

      import java.text.SimpleDateFormat;

Try this code >>

    SimpleDateFormat dcn = new SimpleDateFormat("yyyy-MM-dd");
    String date = dcn.format(jDateChooser1.getDate() );
    jLabel1.setText(date.toString());

Try this:

String date1 = ((JTextField) jDateChooser4.getDateEditor().getUiComponent()).getText() + "";
jLabel1.setText(date1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top