1

I have a JSpinner I would like to show only date(without time) in it.

This is what I do:

SpinnerDateModel model = new SpinnerDateModel();
model.setCalendarField(Calendar.DAY_OF_YEAR);
dataRozpoczeciaSpinner = new JSpinner();
dataRozpoczeciaSpinner.setModel(model);

but the time is also displayed: 27.05.68 00:00

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • 1
    You need to change the format that the editor will use, for [example](http://stackoverflow.com/questions/14451449/jspinner-giving-old-values/14455065#14455065) (it's showing hours and minutes, but I'm sure you get the jist) – MadProgrammer Jun 17 '15 at 08:47
  • Tried that few days ago, usually I just get `IllegalArgumentException`. – Michał Pereświet-Sołtan Jun 17 '15 at 09:21
  • You answered your own question on this topic 4 days ago. `I just get IllegalArgumentException.` well look at your code in that question. You are trying to format a Date when you are using a Time object. Don't you think that might cause a problem? When you ask a question post a proper [SSCCE](http://sscce.org/) demonstrating the problem so we have all the information. – camickr Jun 17 '15 at 14:32

1 Answers1

4

Just try the following:

SimpleDateFormat model = new SimpleDateFormat("dd.MM.yy");
dataRozpoczeciaSpinner = new JSpinner(new SpinnerDateModel());
dataRozpoczeciaSpinner.setEditor(new JSpinner.DateEditor(dataRozpoczeciaSpinner, model.toPattern()));
Anto
  • 4,265
  • 14
  • 63
  • 113