JSpinner.DateEditor()

Help:
Where can I find example on how to use this class?

import java.awt.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.*;
public class tecore extends JFrame {
  public tecore() {
    Date now = new Date();
    SimpleDateFormat sdfDay = new SimpleDateFormat("dd MMM yyyy");
    String today = sdfDay.format(now);
    System.out.println("today = " + today);
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
    String localeTimeToday = df.format(now);
    System.out.println("localeTimeToday = " + localeTimeToday);
    SimpleDateFormat sdfTimeAndDay = new SimpleDateFormat("kkmm   dd MMM yyyy");
    String timeToday = sdfTimeAndDay.format(now);
    System.out.println("timeToday = " + timeToday);
    JLabel label = new JLabel(timeToday, JLabel.CENTER);
    JPanel labelPanel = new JPanel();
    labelPanel.setPreferredSize(new Dimension(200,35));
    labelPanel.add(label);
    SpinnerDateModel model = new SpinnerDateModel(now, null, null,
                                                  Calendar.DAY_OF_WEEK_IN_MONTH);
    JSpinner spinner = new JSpinner(model);
    JSpinner.DateEditor editor = new JSpinner.DateEditor(spinner, "dd MMM yyyy");
    spinner.setEditor(editor);
    JPanel spinnerPanel = new JPanel();
    spinnerPanel.setPreferredSize(new Dimension(200,50));
    spinnerPanel.add(spinner);
    getContentPane().add(labelPanel, "North");
    getContentPane().add(spinnerPanel, "Center");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    pack();
    setVisible(true);
  public static void main(String[] args) {
    new tecore();
}

Similar Messages

  • Change TimeZone in JSpinner.DateEditor?

    I'm trying to figure out how to set the TimeZone associated with a JSpinner.DateEditor. Looks like in 1.4.1 the local TimeZone only is used. In my app I need to use other time zones. I've been through the docs and the source code, but this functionality doesn't seem to be present. Anyone got any hints?

    try note  Note 834520
    Cheers,
    -Sunil

  • Reversing JSpinner / JSpinner.DateEditor

    Hi,
    I have implemented a JSpinner.DateEditor model with code similar to the following:
    SpinnerDateModel startSDM;
    startSDM = new SpinnerDateModel();
    startSDM.setValue(new Date());
    JSpinner startSpinner = new JSpinner(startSDM);
    startSpinner.setEditor(new JSpinner.DateEditor( startSpinner, dateFormat));
    startSpinner.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
              // some unrelevant code...
    myPanel.add(startSpinner);
    startSpinner.setBounds(90, 30, 100, 20);It works fine. However, I feel that it would be more natural for the down arrow to increase the date, not the up arrow. Is there any way this can be easily achieved?
    David.

    override the metods getNextValue() and getPreviousValue()
    of your SpinnerDateModel.
    eg.
    public Object getPrevionsValue(){
      super.getNextValue();
    /and vvI think you can override them directli in this line:
    startSDM = new SpinnerDateModel();

  • JSpinner DateEditor problem

    Hi,
    I have a problem with the JSpinner. When I set a SpinnerDateModel into it, and not define the "full"(eg. MM/dd/yyyy HH: mm a) date format string, then the JSpinner or DateEditor reset the undefined part of time.
    eg.
    -If I not define in the date format string the date part "MM/dd/yyyy" then the JSpinner or the DateEditor is reset the date value of JSpinner to 1970,1,1
    -If I not define in the date format string the time part "HH: mm a" then the JSpinner or the DateEditor is reset the time value of JSpinner to 12:00 AM
    What can I do for not reset the not defined/showed/ part of the time?
    thx.

    The problem is in the format. The format supplied by the standard API does exactly what you described. The alternative is to create your own format or (better) your own formatter.
    I ended up creating my own DateSpinner which is not too difficult.
    Cheers,
    Didier

  • How do I get the active field of DateEditor in JSpinner?

    Hi Everybody,
    I have a JSpinner which uses a DateEditor and displayes the date in "dd/MM/yyyy" format in it. I have over ridden the default behaviour of Up and Down arrow button components of it as per my requirements. Now I want to extend the functionality to change the value of the date on the basis of what is the highlighted field.
    ie if the month is highlighted then the day and year need to
    remain the same but month should increase.and if day is higlited it
    shud follow the normal pattern and if year is highlighted the year should
    move forward keeping the month and date same (no doubt after 12 months increment it is supposed to go to next year). Here is my code:
    <code>
    bq. import java.awt.BorderLayout; \\ import java.awt.Component; \\ import java.awt.event.KeyEvent; \\ import java.awt.event.KeyListener; \\ import java.awt.event.MouseAdapter; \\ import java.awt.event.MouseEvent; \\ import java.awt.event.MouseListener; \\ import java.text.SimpleDateFormat; \\ import java.util.Calendar; \\ import java.util.Date; \\ import java.util.GregorianCalendar; \\ import java.util.StringTokenizer; \\ import javax.swing.JFrame; \\ import javax.swing.JPanel; \\ import javax.swing.JSpinner; \\ import javax.swing.SpinnerDateModel; \\ import javax.swing.SpinnerModel; \\ /** \\ * \\ */ \\ /** \\ * @author asmarwal \\ * \\ */ \\ public class MySpinnerDemo extends JPanel implements MouseListener { \\ static JPanel myPanel; \\ static int day = 0; \\ static int month = 0; \\ static int year = 0; \\ static String date; \\ static JSpinner.DateEditor de = null; \\ static Calendar calendar = Calendar.getInstance(); \\ public MySpinnerDemo(){ \\ // Let's see it later if we need to do sth here \\ myPanel = new JPanel(new BorderLayout()); \\ } \\ private static JSpinner getSpinner(){ \\ // initDate, earliestDate & latestDate might be taken from constructor too \\ Date nowDate = calendar.getTime(); \\ calendar.add(Calendar.YEAR, 0); \\ Date earliestDate = calendar.getTime(); \\ Calendar latestCal = new GregorianCalendar(9999, Calendar.DECEMBER, 31); \\ Date latestDate = latestCal.getTime(); \\ System.out.println("InitDate:: "+nowDate+"\n Earliest Date:: "+earliestDate+"\n Latest Date:: "+latestDate); \\ SpinnerModel dateModel = new SpinnerDateModel(nowDate, \\ earliestDate, \\ latestDate, \\ Calendar.YEAR);//ignored for user input \\ JSpinner spinner = new JSpinner(dateModel); \\ Calendar currCal = new GregorianCalendar(); \\ spinner.setValue(currCal.getTime()); \\ spinner.setEditor(new JSpinner.DateEditor(spinner, "dd/MM/yyyy")); \\ spinner.setUI(new javax.swing.plaf.basic.BasicSpinnerUI() { \\ protected Component createNextButton() { \\ Component u = super.createNextButton(); \\ u.addMouseListener(new MouseAdapter() { \\ public void mouseClicked(MouseEvent me){ \\ System.out.println("You have just clicked the up arrow button of UI component..."); \\ calendar.add(Calendar.DATE, 1); \\ spinner.setValue(calendar.getTime()); \\ myPanel.repaint(); \\ } \\ }); \\ return u; \\ } \\ //Down Arrow button \\ protected Component createPreviousButton() { \\ Component u = super.createNextButton(); \\ u.addMouseListener(new MouseAdapter() { \\ public void mouseClicked(MouseEvent me){ \\ System.out.println("You have just clicked the down arrow button of UI component... ActiveField:: "); \\ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); \\ Calendar calToday = new GregorianCalendar(); \\ String calTodaDateStr = sdf.format(calToday.getTime()); \\ String spinnerCurrDateStr = sdf.format(calendar.getTime()); \\ //Checking if spinner's current date value is today's.. \\ // If yes then go to 31/12/9999 else perform normal date decrement \\ if(spinnerCurrDateStr.equalsIgnoreCase(calTodaDateStr)){ \\ System.out.println("IF:: spinnerCurrDateStr: "+spinnerCurrDateStr+" calTodaDateStr"+calTodaDateStr); \\ Calendar newCal = new GregorianCalendar(9999, Calendar.DECEMBER, 31); \\ //    Set the static var calendar's value to the current system date \\ calendar = new GregorianCalendar(); \\ spinner.setValue(newCal.getTime()); \\ }else{ \\ System.out.println("ELSE:: spinnerCurrDateStr: "+spinnerCurrDateStr+" calTodaDateStr"+calTodaDateStr); \\ calendar.add(Calendar.DAY_OF_MONTH, (-1)); \\ spinner.setValue(calendar.getTime()); \\ } \\ myPanel.repaint(); \\ } \\ public void mousePressed(MouseEvent me){ \\ System.out.println("You have just kept pressed the down arrow button of UI component..."); \\ // Don't do anything \\ calendar.add(Calendar.DAY_OF_MONTH, 0); \\ spinner.setValue(calendar.getTime()); \\ myPanel.repaint(); \\ } \\ }); \\ return u; \\ } \\ }); \\ return spinner; \\ } \\ public void mouseClicked(MouseEvent e) { \\ // TODO Auto-generated method stub \\ } \\ public void mouseEntered(MouseEvent e) { \\ // TODO Auto-generated method stub \\ } \\ public void mouseExited(MouseEvent e) { \\ // TODO Auto-generated method stub \\ } \\ public void mousePressed(MouseEvent e) { \\ // TODO Auto-generated method stub \\ } \\ public void mouseReleased(MouseEvent e) { \\ // TODO Auto-generated method stub \\ } \\ /** \\ * @param args \\ */ \\ public static void main(String[] args) { \\ // TODO Auto-generated method stub \\ JFrame frame = new JFrame("JSpinner Sample"); \\ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); \\ MySpinnerDemo msd = new MySpinnerDemo(); \\ //System.out.println("msd.getSpinner():: "+msd.getSpinner()); \\ myPanel.add(getSpinner(), BorderLayout.CENTER); \\ frame.getContentPane().add(myPanel, BorderLayout.SOUTH); \\ frame.setSize(200, 90); \\ frame.setVisible(true); \\ } \\ }
    </code>
    Thanks in advance!

    Simmi,
        you need to check in SE11(data dictionary) with the specified tachnical names.
    comming to selective deletion...
    divide the data into segments based on the organizational values.
    take the material group. check with any consultant. ask simple qustion how many material group we have?
    take the case 5 mat1, mat2, mat3, mat4, mat5. Delete the values based on that. Menas that... entire infocube defined into 5 segments.
    Before deleting make sure u have taken correct charecterstic. if you can give us the scenario we can let you know how can we delete the data with out effecting existing business process.
    alll the best.
    Regards,
    Nagesh Ganisetti.

  • MaskFormatter with JSpinner and DateEditor?

    Hi,
    I'm trying to apply a MaskFormatter to the DateEditor on a JSpinner. We want the ability to both manually edit the fields by hand AND/OR click the up/down arrows.
    The one gotcha is that when manually entering the values, we want to set a mask on the field so the user doesn't have to type in the ":" when separating the time fields. Right now, when they can delete all the text in the spinner textfield.
    I've dug through the source code of JSpinner and it appears that I should be able to get the editors JFormattedTextField and set the MaskFormatter as part of the AbstractFormatFactory. But all I end up with is a blank JSpinner and I can't type in the textfield.
    Below is my code:
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.util.Calendar;
    import java.util.Date;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSpinner;
    import javax.swing.SpinnerDateModel;
    import javax.swing.SpinnerModel;
    import javax.swing.text.DefaultFormatterFactory;
    import javax.swing.text.MaskFormatter;
    public class MaskedFieldTest {
         public static void main(String[] args) {
              final JFrame f = new JFrame("Textfield demo");
              f.setDefaultCloseOperation(f.DISPOSE_ON_CLOSE);
              f.addWindowListener(new WindowAdapter() {
                   public void windowClosed(WindowEvent e) {
                        System.exit(0);
              f.setSize(250, 70);
              try {
                   // Create a spinner
                   JSpinner spinner = new JSpinner();
                   // Set up a dummy calendar for the model
                   Calendar calendar = Calendar.getInstance();
                   Date initDate = calendar.getTime();
                   calendar.add(Calendar.YEAR, -100);
                   Date earliestDate = calendar.getTime();
                   calendar.add(Calendar.YEAR, 200);
                   Date latestDate = calendar.getTime();
                   // Set the model
                   SpinnerModel dateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);
                   spinner.setModel(dateModel);
                   // Create the dateeditor using the time format we want displayed in the spinner
                   JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(spinner, "hh:mm:ss a");
                   // Create a mask for editing so we don't have to manually add the :
                   MaskFormatter fmt = new MaskFormatter("##:##:## UU");
                   // Get the factory from the editor and set the maskformatter for the editing portion
                   DefaultFormatterFactory form = (DefaultFormatterFactory)dateEditor.getTextField().getFormatterFactory();
                   form.setEditFormatter(fmt);
                   // Finally, assign the editor to the spinner
                   spinner.setEditor(dateEditor);
                   // Display the panel
                   JPanel panel = new JPanel();
                   panel.add(spinner);
                   f.getContentPane().add(panel);
                   f.setVisible(true);
              } catch (java.text.ParseException e) {
                   e.printStackTrace();
    }If you run the code, you'll just get an empty JSpinner and you can't do anything in the textfield even though it is enabled.
    I'm running JDK.1.4.2_09 on Windows XP SP2
    Has anyone used a MaskFormatter with a DateEditor on a JSpinner before?
    Thanks,
    - Tim

    see weebib's post here
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=581804

  • How to display the values in JSpinner in format  day:HH:mm

    Hi All,
    I want to know how can I display the values inside a JSpinner in the format day:HH:mm. Here the value of 'day' can be anything say from 0 to 365 and HH stand for hour and mm stands for minutes.
    I tried to implement it using
    mSpinner.setEditor(new JSpinner.DateEditor(mSpinner, "DD:HH:mm"));
    but here the values of day was not proper. Please let me know if there is any standard format or how can I configure my own editor.
    Thanks,
    Rohit.

    Hi,
    It worked well for 112 as 112 comes under April month.. i.e. it will work properly for the range 91 to 120 as the current month is April and if we start counting from january 01 then for April month , the number of day will fall under range 91 to 120.
    See, it will allow you to change the values beyond the limit (i.e. less than 91 or more than 120) but the real problem is that I used this spinner in the table and when I will try to save the value of spinner , then if the value of day in beyond the limit 91 to 120 then it will automatically changing in the range between 91 to 120.
    I tried to use format DD:HH:mm ...... do I need to use any other format..
    Hi All,
    I want to know how can I display the values inside
    de a JSpinner in the format day:HH:mm. Here thevalue
    of 'day' can be anything say from 0 to 365 and HH
    stand for hour and mm stands for minutes.
    I tried to implement it using
    mSpinner.setEditor(newJSpinner.DateEditor(mSpinner,
    , "DD:HH:mm"));
    but here the values of day was not proper. Define "not proper". I just tried it and it displayed
    day 112 for today which seems correct.

  • JSpinner problems with alignment of text

    I experience problems with the alignment of the text within the spinner. I read a few topics on this forum. Many answers point to the solution of grabbing the JFormattedTextField from the spinner and call the setHorizontalAlignment(int) method. Seems hat doesn't work for me.
    Here is the code I wrote:
    SpinnerDateModel dateModel = new SpinnerDateModel();
    JSpinner dateSpinner = new JSpinner(dateModel);
    JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)dateSpinner.getEditor();
    JFormattedTextField tf = dateEditor.getTextField();
    tf.setHorizontalAlignment(JFormattedTextField.RIGHT);
    maybe I am missing something. Please help!
    Thank You in advance.

    I'm not sure if this is the solution, but the getTextField() Method should be called on a JSpinner, rather than a SpinnerDateModel. I took this Method from the Swing Tutorial and made it static, so i could use it anywhere:
    public static JFormattedTextField getTextField(JSpinner spinner) {
              JComponent editor = spinner.getEditor();
              if (editor instanceof JSpinner.DefaultEditor) {
                   return ((JSpinner.DefaultEditor)editor).getTextField();
              } else {
                   System.err.println("Unexpected editor type: "
                                          + spinner.getEditor().getClass()
                                          + " isn't a descendant of DefaultEditor");
                   return null;
         }Besides, setting an Editor for this JSpinner is not neccesary, because it is chosen automaticaly. You only need to do so if you have implemented a custom SpinnerModel.
    Hope this was any help...

  • Change displayed time zone within a JSpinner - Help!

    Hi,
    I have a JSpinner formated to use a date model. The format of the text displayed includes the time zone. The time zone displayed is my local time zone and I would like it to be a different time zone (Etc/UTC). I have tried setting the time zone of date the spinner is intialized with as well as the SimpleDateFormat string passed into the editor, but the spinner still displays the local time zone. I have been searching online and in the forums and while I've found lots of issues with using the date model spinner, I haven't found this particular issue. Any help is greatly appreciated!!
    Here is my code:
    // Save off the current date and time
    GregorianCalendar now = new GregorianCalendar();
    // Set the timezone to be UTC
    now.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
    // Create a date/time spinner with a default value of the current
    // date and time, no upper or lower bounds, and can be
    // incremented by the minute.
    JSpinner myTimeSpinner = new JSpinner(
       new SpinnerDateModel(now, null, null, Calendar.MINUTE)
           // This empty method is needed for the MINUTE increment
           // to work; otherwise it increments by the first field
           // in the display
           public void setCalendarField(int field){}
    // Define a time format to be used
    SimpleDateFormat myTimeFormat =
       new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    // Set the time zone on the format
    myTimeFormat.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
    // Set the editor to use the defined time format
    myTimeSpinner.setEditor(
       new JSpinner.DateEditor(myTimeSpinner,
       myTimeFormat.toPattern()));Thanks again!
    Naomi

    When you call myTimeFormat.toPattern(), you are losing the time zone information. You need to instantiate the JSpinner.DateEditor, then call:
    editor.getFormat().setTimeZone(TimeZone.getTimeZone("Etc/UTC"))

  • JSpinner and MouseListener for EzCalendar

    hi,
    has anybody succesfully set a MouseListener to a JSpinner? I've tried to set it to the Spinner directly, to it's Editor, even to the underlying Component, but my MouseListener is never activated. It seems the JSpinner consumes all the mouse events itself without passing them on.
    Background: I'd like to catch right-button clicks on a JSpinner.DateEditor to pop up the EzCalendar which was discussed her recently.
    Any ideas are welcome...
    Klaus

    FYI:
    ((JSpinner.DefaultEditor) mySpinner.getEditor()).getTextField.addMouseListener(myMouseListener);dit it. The MouseListener had to be added to the underlying FormattedTextField. Duh!

  • JSpinner with SpinnerDateModel - how to set a different Locale?

    I wonder, how I can get my JSpinner to display dates in some different Locale.
    I tried UIManager.getDefaults().setDefaultLocale(...) and spinner.setLocale(...) and ((JSpinner.DateEditor)spinner.getEditor()).setLocale(...) and ((JSpinner.DateEditor)spinner.getEditor()).getTextField.setLocale(...) but without any effect.
    ??? "Lost in Swing" ???

         * Set the same DateEditor properties
         * for each spinner.
         * @param dateEditor
         * @param pattern
         public void setFormattedDateEditorTextField(JSpinner.DateEditor dateEditor, String pattern) {
              JFormattedTextField jFormattedTextField = dateEditor.getTextField();
         jFormattedTextField.setEditable(false);
              jFormattedTextField.setPreferredSize(new Dimension(130, 15));
              jFormattedTextField.setHorizontalAlignment(JFormattedTextField.RIGHT);
              //setFontSyleProperties((Component)jFormattedTextField);
              jFormattedTextField.setLocale(getSpecifiedLocale());
              DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT, getSpecifiedLocale());
              ((SimpleDateFormat)dateFormat).applyPattern(pattern);
              ((DateFormatter)jFormattedTextField.getFormatter()).setFormat(dateFormat);
              jFormattedTextField.getFormatterFactory().getFormatter(jFormattedTextField).install(jFormattedTextField);
         }

  • JSpinner editable, how to validate input??

    Hi everybody,
    i've a spinner made like this:
    spinner_ora_inizio = new JSpinner();
    spinner_ora_inizio.setModel(new SpinnerDateModel());
    spinner_ora_inizio.setEditor(new JSpinner.DateEditor(spinner_ora_inizio, "dd/MM/yyyy HH.mm"));
    i'm having trouble to find out when the the user inputs invald values.
    Example: if my user inputs "kfdkjghdfjkghd" and press "Save" the getValue methods returns the last valid value and i dont know how to make input validation..
    Thank you

    Sure seems like there should be SOME way to make this work.
    I've tried a FocusListener on the JSpinner, and on it's Editor. Never gets called.
    I've tried an InputVerifier on JSpinner, never gets called.
    I've tried setting the FocusPolicy to COMMIT. That commits the value, but the inputVerifier never gets called.
    Does anyone have a Known WORKING technique to do value validation on a JSpinner using the NumberModel?
    When you click or tab away from a JSpinner that you just typed a number into, I would like to validate that value. If it's over the max, I'll set it to the max, if it's under the min, I'll set it to the min.
    And note, I'm talking about the user TYPING into the field, not using the spinner buttons.
    It seems like SOMEBODY will have figured out how to do this.

  • Update the JSpinner/SpinnerDateModel at runtime.

    I'm having trouble updating the the value of of JSpinner field at runtime. The scenario is;
    Once the application is started the default system date/time is set on my JSpinner field. If I visit my page that contains the said Date (JSpinner) feild, it will show the time the system was started. But I always want to display the current date/time, at the time I visit the page, in the JSpinner Date field.
    The hierarchy of the code is;
    JPanel1 (base class)
    --- JPanel2
    --- JTabbedPane (consists of a couple of tabs, one of which is Jpanel3)
    --- Jpanel3 (different class by itself, which contains the desired JSpinner Date field)
    In JPanel3 I have implemented JSpinner as;
        public JSpinner getDateSpinnerField ()
            SpinnerDateModel dateModel= new SpinnerDateModel();
            dateModel.setCalendarField( Calendar.MONTH );
            JSpinner spinner= new JSpinner( dateModel);
            JSpinner.DateEditor dateEditor = new JSpinner.DateEditor( spinner, "MM/dd/yyyy HH:mm:ss" );
            dateEditor .getTextField().setEditable( false );
            spinner.setEditor( dateEditor );
            fromSpinner.addChangeListener( new javax.swing.event.ChangeListener() {
                public void stateChanged ( javax.swing.event.ChangeEvent e )
                    JSpinner jSpinner = (JSpinner)e.getSource();
                    SpinnerDateModel spinnerDateModel = (SpinnerDateModel)jSpinner.getModel();
                    setDateValue( spinnerDateModel.getDate() );
            return spinner;
        }Let me know if I need to paste the code as well and/or if any one needs any clarifications.
    thanks

    No, the the setDateValue() is for a different purpose here. It's just a setter and getter which holds the date value whenever user is modifying it. Lets not get diverted from the issue at hand.
    Also I have added a ChangeListener event on my tabbed pane, as implemneted below;
           <JTabbedPane>.addChangeListener( new javax.swing.event.ChangeListener() {
                    public void stateChanged ( javax.swing.event.ChangeEvent e )
                        int tabPosition = ( (JTabbedPane)e.getSource() ).getSelectedIndex();
                        JTabbedPane pane = (JTabbedPane)e.getSource();
                        if ( tabPosition == 1 ) {
                            System.out.println( "tabPosition: " + tabPosition );
                            Jpanel3 panel = ( Jpanel3 )pane.getSelectedComponent();
                            final JSpinner spinner = panel.getFromSpinnerField();
                            DateEditor editor = ( (DateEditor)spinner.getEditor() );
                            final SpinnerDateModel dateModel = editor.getModel();
                            dateModel.setValue( new Date() );
                            System.out.println("Value1: {"+dateModel.getValue()+"}");
                            try {
                                editor.commitEdit();
                                editor.repaint();
                                editor.revalidate();
                            catch ( ParseException pe ) {
                                System.out.println( "Exception" );
                                pe.printStackTrace();
                            SwingUtilities.invokeLater( new Runnable() {
                                public void run() {
                                    //spinner.invalidate();
                                    spinner.repaint();                       
                                    spinner.revalidate();
                                    System.out.println("Value2: {"+dateModel.getValue()+"}");
    But the date in the JSpinner feild doesn't get updated.
    thanks
    Edited by: javanuts on Mar 12, 2008 3:39 PM

  • Set default time in jSpinner?

    I'm looking for the correct syntax to use for setting a default time in the jSpinner object. Something along the lines of:
    mySpinner.setValue("08:00");
    which I know doesn't work. What would be the correct syntax?
    Thanks.

    I did that by using SpinnerDateModel.
    Create the Date object with the default time 08:00.
    See the following sample,
        Date date = new Date(2010,1,1,8,0);
        SpinnerDateModel sm = new SpinnerDateModel(date, null, null, Calendar.HOUR_OF_DAY);
        JSpinner spinner = new JSpinner(sm);
        JSpinner.DateEditor de = new JSpinner.DateEditor(spinner, "hh:mm");
        spinner.setEditor(de);Hope, this will help you.

  • JSpinner & FocusListener Problem

    Hey all....
    Im trying to add a focusListener to a JSpinner so that when the spinner looses focus it saves its value in a database...
    But i cant seem to get it to work, i tried to add the listener on the spinner, on the editor and on the textfield from the editor and none of them work....
    what am i missing or can this be done????
    thanks

    ok heres the code
    public class CaddyTimeField extends JSpinner implements CaddyWidget
    private DataBean bean;
    private boolean isDirty = false;
    private CaddyPanel parent;
    private int dataType;
    private String propertyName;
    public CaddyTimeField()
    super();
    init();
    public CaddyTimeField(String propertyName)
    super();
    init();
    this.propertyName = propertyName;
    private void init()
    Calendar cal = new GregorianCalendar(0, 0, 0, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    SpinnerDateModel sdm = new SpinnerDateModel(cal.getTime(), null, null, Calendar.MINUTE);
    sdm.setCalendarField(Calendar.MINUTE);
    this.setModel(sdm);
    try
    this.commitEdit();
    catch (Exception e)
    Trace.traceError(e);
    JSpinner.DateEditor editor = new JSpinner.DateEditor(this, "HH:mm");
    this.addChangeListener(new javax.swing.event.ChangeListener()
    public void stateChanged(javax.swing.event.ChangeEvent e)
    setDirty(true);
    this.addFocusListener(new FocusListener()
    public void focusGained(FocusEvent e){}
    public void focusLost(FocusEvent e)
    if(isDirty)
    setBeanValues();
    this.setEditor(editor);
    private void getBeanValue()
    try
    Class c = bean.getClass();
    Method meth = c.getMethod("get" + propertyName, null);
    Object obj = meth.invoke(bean, null);
    if(obj != null)
    this.setValue(obj);
    catch(NoSuchMethodException mex){Trace.traceError(mex);}
    catch(IllegalAccessException aex){Trace.traceError(aex);}
    catch(InvocationTargetException itex){Trace.traceError(itex);}
    catch(Exception ex){Trace.traceError(ex);}
    public void setBeanValues()
    try
    Time time = new Time(((Date)this.getValue()).getTime());
    Class c = bean.getClass();
    java.lang.reflect.Method meth = null;
    Class[] args = { Class.forName("java.sql.Time") };
    meth = c.getMethod("set" + propertyName, args);
    Object[] args2 = { time };
    Object obj = meth.invoke(bean, args2);
    catch(ClassNotFoundException cex){Trace.traceError(cex);}
    catch(NoSuchMethodException mex){Trace.traceError(mex);}
    catch(IllegalAccessException aex){Trace.traceError(aex);}
    catch(java.lang.reflect.InvocationTargetException itex) {Trace.traceError(itex);}
    catch(Exception ex){Trace.traceError(ex);}
    public void setBean(DataBean bean)
    this.bean = bean;
    if(bean != null)
    getBeanValue();
    public void setParent(CaddyPanel parent)
    this.parent = parent;
    public void setDirty(boolean isDirty)
    this.isDirty = isDirty;
    if(parent != null)
    parent.setDirty(true);
    }

Maybe you are looking for

  • Different output observed in IE8 and IE11 for same HTML file

    when I open the below html code in ie8 and ie11 the output is different. <div style=" color: EAE6F1; " id="Screen147"> <img style=" width: 1280; height: 1020; " id="item1" src="Desert.jpg" border="0"/> <div style=" background-color: FFFFFF; color: 00

  • Some Sent messages are missing

    My wife has noticed that about 5-10% of the emails she sends are not in the Sent folder. When we checked the Console it gives the following error: Error (null) occurred while trying to append messages to outgoing store. Ignoring and proceeding delive

  • Help with CDOSYS,  and insert into DB

    I'm using Dreamweaver 8, SQL Server 2000, Windows 2003 Server. This is what so far I was able to achieve. Have a form that inserts records into the database, a confirmation page of the insert, and a simple CDOSYS message to notify me that a record ha

  • Reinstalling from backup - Windows

    My hard drive was replaced, but I had a backup so I copied the adobe files from the following folders: Program files, Program files 86X, Users (desktop). I can see the files there, including the installation instructions and my reciept from adobe wit

  • Trying to reuse an already used ipod.

    This ipod has already been disconnected from its original computer.  If i reset it to factory setting will the music on it dis appear from the ipod alone or also from the original computer?  I do not need to back up it for myself but the original own