title: Using JSpinner to get values
body: <p>I am using <code>JSpinner</code> for selecting time in HH:MM:SS format. Whenever 
  i open the GUI the spinner sets automatically to current system time,
  What I need is say for example if I click save after giving some value to spinner and when
  I again open it the old values should be shown.</p>
  
  <p>I have tried following code but its not working,</p>
  
  <pre><code>if(Stime != null){
              Date time = new SimpleDateFormat("HHMMSS", Locale.ENGLISH).parse(Stime);
              StarttimeSpinner.setValue(time);
  }
  </code></pre>
  
  <p>where Stime is the previously saved time in HHMMSS format e.g(142030)</p>
  
  <p>is it correct? or how can i do it? Please help! </p>
  
  <p>EDIT:</p>
  
  <pre><code>    SpinnerModel Startmodel = new SpinnerDateModel();
      StarttimeSpinner = new JSpinner();
      StarttimeSpinner = new JSpinner(Startmodel);
      JComponent editor = new JSpinner.DateEditor(StarttimeSpinner, "HH:mm:ss");
      StarttimeSpinner.setEditor(editor);
  
     try{ 
          if(!(Stime.equalsIgnoreCase("")))
              {
              Date time = new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH).parse(Stime);
              SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");  
              String dateString = formatter.format(time);
              StarttimeSpinner.setModel(new SpinnerListModel(new String[]{dateString}));
  
          }
      }
      }catch(Exception ie){
          System.err.println("in time panel");
      }
  </code></pre>
  
  <p>Stime format is HHmmss and its a string.In dateString(Variable) i get the previous value in HH:mm:ss format but its not being set in Spinner instead showing the system time.</p>
  
  <p><strong>EDIT 2:</strong>
  I have Found out a solution but with a bug,</p>
  
  <p>If my code is like this(1),</p>
  
  <pre><code> StarttimeSpinner = new JSpinner();
               SpinnerModel Startmodel = new SpinnerDateModel();
              StarttimeSpinner = new JSpinner(Startmodel);
              JComponent editor = new JSpinner.DateEditor(StarttimeSpinner, "HH:mm:ss");
              StarttimeSpinner.setEditor(editor);
  </code></pre>
  
  <p>The below piece of code works fine,</p>
  
  <pre><code>Date starttime = new Date();
  starttime = (Date)StarttimeSpinner.getValue();
  </code></pre>
  
  <p>if i change the code like below(2),</p>
  
  <pre><code>Date time = new SimpleDateFormat("HHmmss", Locale.ENGLISH).parse(Stime);
          SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");  
          String dateString = formatter.format(time);
          StarttimeSpinner.setModel(new SpinnerListModel(new String[]{dateString}));
  </code></pre>
  
  <p>where Stime is (e.g)120011</p>
  
  <p>The below piece of code doesn't work fine,</p>
  
  <pre><code>Date starttime = new Date();
  starttime = (Date)StarttimeSpinner.getValue();
  </code></pre>
  
  <p>and throwing Exception as <code>java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date</code> at get value statement.</p>