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

Similar Messages

  • Jspinner weird problem

    Hi all,
    I have this weird problem with Jspinners when I try to run this code. When I run it, the second spinner shows the date (while the first one only shows the time) and they are both larger than they are supposed to be (try resizing after it shows up)
    Any help would be greatly appreciated.
    // CODE STARTS HERE ////////////////////////////////
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    public class Test {
         public static void main(String args[]) {
              TimeSpinner spin1 = new TimeSpinner();
              TimeSpinner spin2 = new TimeSpinner();
              JFrame frame = new JFrame();
                   frame.getContentPane().setLayout(new FlowLayout());
                   frame.getContentPane().add(spin1);
                   frame.getContentPane().add(spin2);
                   frame.setSize(300,300);
                   frame.show();
    class TimeSpinner extends JSpinner {
         public TimeSpinner() {
              super();
              // spinner date model
              SpinnerDateModel sdm = new SpinnerDateModel();
              sdm.setCalendarField(Calendar.MINUTE);
              this.setModel(sdm);
              try {
                   this.commitEdit();
              } catch (Exception e) {
                   e.printStackTrace();
              JSpinner.DateEditor de = (JSpinner.DateEditor)this.getEditor();
              de.getFormat().applyPattern("hh:mm a");
         public void setFixedSize(int width, int height) {
              Dimension fixedDimension = new Dimension(width, height);
              this.setMinimumSize(fixedDimension);
              this.setMaximumSize(fixedDimension);
              this.setPreferredSize(fixedDimension);

    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

  • 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

  • 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);
    }

  • 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()

    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();
    }

  • JSpinner format problem

    Hi guys,
    I am trying to create a JSpinner with the following format HH:MM but it is not working. The spinner keeps displaying both the date and the time. Can somebody tell me what's wrong with my code? I would really appreciate it ...
    import java.awt.*;
    import java.text.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class Test {
    public static void main(String[] args) {
              Frame f = new Frame();
              f.setLayout(new BorderLayout());
              f.add(new TimeSpinner(), BorderLayout.WEST);
              f.add(new TimeSpinner(), BorderLayout.EAST);
    f.setVisible(true);
              f.pack();
    class TimeSpinner extends JSpinner {
         public TimeSpinner() {
              super();
              // spinner date model
              SpinnerDateModel sdm = new SpinnerDateModel();
              sdm.setCalendarField(Calendar.MINUTE);
              this.setModel(sdm);
              try {
                   this.commitEdit();
              } catch (Exception e) {
                   e.printStackTrace();
              JSpinner.DateEditor de = (JSpinner.DateEditor)this.getEditor();
              de.getFormat().applyPattern("hh:mm a");

    Hey you were close, try this:
    import java.awt.*;
    import java.text.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class Test{
         public static void main(String[] args) {
              Frame f = new Frame();
              f.setLayout(new BorderLayout());
              f.add(new TimeSpinner(), BorderLayout.WEST);
              f.add(new TimeSpinner(), BorderLayout.EAST);
              f.setVisible(true);
              f.pack();
    class TimeSpinner extends JSpinner {
         public TimeSpinner() {
              super();
              // spinner date model
              SpinnerDateModel sdm = new SpinnerDateModel();
              sdm.setCalendarField(Calendar.MINUTE);
              this.setModel(sdm);
              try {
                   this.commitEdit();
              } catch (Exception e) {
                   e.printStackTrace();
              JSpinner.DateEditor editor = new JSpinner.DateEditor(
    this, "hh:mm a");
    this.setEditor(editor);
    }

  • JSpinner model problem

    Hello,
    I have an application which let you insert data of a music album. All this data goes into a database. One of the possible fields is the length of the album.
    I thought about using a JSpinner and using a SpinnerDateModel but this gives me some problems.
    To make it easy for the user i would like to enter the time in following format: mm:ss. But the problem here is that the minutes only goes to 59. But it should not be limited to 59, to make it the same as the time indicated on your music player. For example: 75minutes:24seconds.
    Is this possible with a SpinnerDateModel? Or should I use something else?
    Thx

    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.

  • JSpinner Using Problem

    Hey guys, I'm new to the JAVA programming world and i have a little problem...
    I read the API of the JSpinnerNumberModel but i don't know, using NetBeans, how to set the "only positivie values range" for the JSpinner...
    I know is a noob question but i hope someone will help me...Thanks!!

    According to this posting the OP has the answer:
    http://forum.java.sun.com/thread.jspa?threadID=5200948

  • JSpinner stateChanged Problem!!!!

    Hello,
    I have an Application where i am using one Jspinner and Jlist. From Jlist i am changing maximum value for the Jspinner. Here occures problem, When any Value changed in Jspinner it's call the method stateChanged().
    But in method stateChanged i am doing another things, which doesnot gives me correct result.
    Is there any way to prevent from the problem.Just want to know is ther any way that, when i change the maximum value from The jlist, it does not invoke method stateChange().
    thank'x in Advance.

    I use the setEnabled(boolean) method to achive this. Assume we have a JSpinner js, I need three lines of code js.setEnabled(false);  //switch off firing of events
    js.getModel().setValue(new Integer(whatever));
    js.setEnabled(true);  //switch on firing of eventsThis works for most classes that extend JComponent (JSlider, etc).

  • 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...

  • Problems in JSpinner

    Hi,
    I am trying to create timefield using JSpinner similar to TimeField in
    Date/Time Properties dialog in Microsoft Windows. Here is the code i have
    written
    import javax.swing.*;
    import javax.swing.event.*;
    import java.text.*;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.text.*;
    public class MySpinner {
    JFormattedTextField tf;
    public MySpinner(){
    JFrame frame = new JFrame("Spinner");
    frame.setDefaultCloseOperation(3);
    final SpinnerDateModel model = new SpinnerDateModel();
    JSpinner spinner = new JSpinner(model);
    JSpinner.DateEditor editor = new JSpinner.DateEditor(spinner,"HH:ss:mm");
    spinner.setEditor(editor);
    tf =((JSpinner.DateEditor)spinner.getEditor()).getTextField();
    tf.setEditable(true);
    tf.setBackground(Color.white);
    tf.setSelectionColor(Color.blue);
    tf.setSelectedTextColor(Color.white);
    DefaultFormatterFactory factory
    =(DefaultFormatterFactory)tf.getFormatterFactory();
    DateFormatter formatter = (DateFormatter)factory.getDefaultFormatter();
    formatter.setAllowsInvalid(false);
    frame.getContentPane().add(spinner, BorderLayout.SOUTH);
    frame.pack();
    frame.show();
    public static void main (String args[]) throws Exception {
    new MySpinner();
    It works just fine when i use up/down keys or spinner at the right to change
    the time. But when i try to
    modify the time by editing the TimeField it is not behaving as expected.
    I want it such that Timefield should allow user to change the time using
    Spinner as well as by editing the
    timefield. But it should not allow the user to enter invalid time.
    Please give me your suggestions. Am I missing something here?
    Thanks in advance.
    Abhijeet

    Hi J�rg,
    Thanks for your reply.
    I wrote a standalone version simulating the problem I have and -- guess what -- it worked fine.
    The only feasible difference between the two programs is that for the demo program I coded the layout and placement of the components myself, whereas with the problem code, I used IntelliJ's GUI builder, which uses its own layout manager. This must have something to do with the problem.
    However, I have managed to botch a fix -- first I set the JSpinners' values to 0, THEN set them to the random numbers. Weird, but works.
    Thanks again, though.
    Regards.

  • 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.

Maybe you are looking for

  • IMac + Canon pixma mp 500

    Hi, I cannot get my IMac to connect to my Canon Pixma MP500. I went to the canon site and it says: There is no driver for the OS Version you selected. The driver may be included in your OS or you may not need a driver. And the options my Mac provides

  • Instanciate generic subclass of an abstract class

    Hello, I'm writing a litle file manager API for my application, organised like a Database: a table filled by records. I want my table to be able to be able to manage different types of records (but one record type by table!), so I have this hierarchy

  • Battlelog (for battlefield 3) does not work with Firefox 15.0.1. It works fine with the older Firefox 14.0.1

    The flash features on the Battlefield 3 site - battlelog.battlefield.com do not work when Firefox updates itself to 15.0.1 It does not load the pages correctly or does it let you select/ click on anything in the flash parts. When I uninstalled 15.0.1

  • Preserving XML "special" characters in output

    I've got a valid XML document that may contain special characters, such as ampersands. These characters are properly escaped in the document (i.e., + is represented as amp; ). When I parse this document (using either the Java V2 parser or the PL/SQL

  • Why doesn't my mail arrive in the inbox?

    I have a .mac account and can only get my mail by going online. Thanks!