0

i have a code like this

    JXDatePicker picker = new JXDatePicker();
    //picker.setDate(Calendar.getInstance().getTime());
    picker.setFormats(new SimpleDateFormat("dd.MM.yyyy"));
    picker.setDate(Calendar.getInstance().getTime());
    picker.setBounds(50,130,100,25);
    f.add(picker);

now i want to display date into console how to do this?

  • 1) `picker.setBounds(50,130,100,25);` Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). 2) *"want to display date into console"* `System,out.println(theDate);` but given this is an application with a GUI, displaying the date in the console seems like a bad idea. – Andrew Thompson Jul 23 '16 at 07:40
  • @AndrewThompson actually i want to check whether it is working or not. if it works properly then i want to store same date into database. if any solution please provide.Thanks in advance – Hitesh Ovhal Jul 23 '16 at 09:26
  • So.. did you try my suggestion for confirming it was working? Is it working? I have no knowledge of DBs (but lots with Swing) and storing the date to a DB is ***not*** something I can help with. But the way you're saying things seems like you want a complete example or 'help desk' level of help, and SO is not the place to find either.. – Andrew Thompson Jul 23 '16 at 11:32

1 Answers1

0

For displaying date into console you can do the following:

SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
picker.setFormats(formatter);
System.out.println(formatter.format(picker.getDate()));

But as @AndrewThompson said, in GUI application, displaying date on console is a bad idea. Instead you can show it in a JLabel if you want.

Jay Patel
  • 378
  • 6
  • 18