Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSpinners with shared SpinnerModel

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?

like image 667
vaughandroid Avatar asked Jan 29 '26 05:01

vaughandroid


1 Answers

Maybe the CyclingSpinnerListModel found in the Swing tutorial on How to Use Spinners will give you some ideas.

like image 141
camickr Avatar answered Jan 30 '26 18:01

camickr