I’m trying to set up multiple JSpinners to edit a single Date value – i.e. one spinner for days, one for months, etc.
It seems like I ought to be able to share a single SpinnerModel between several JSpinners, but I’m running into difficulties with this approach.
What I tried was essentially as follows:
SpinnerDateModel model = new SpinnerDateModel();
JSpinner dayPeer = new JSpinner(model);
dayPeer.setEditor(new JSpinner.DateEditor(dayPeer, "dd"));
JSpinner monthPeer = new JSpinner(model);
monthPeer.setEditor(new JSpinner.DateEditor(monthPeer, "MM"));
When doing this, I found that changing one value reset the other one. The problem seemed to originate in JSpinner.DefaultEditor.propertyChange(), which parses the editor text into a date, then calls setValue() with that.
So, it looks like I also need to implement a custom editor component with a custom propertyChange() method. Am I finally on the right track, or have I missed something obvious?
Maybe the
CyclingSpinnerListModelfound in the Swing tutorial on How to Use Spinners will give you some ideas.