Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot override SpinnerListModel.findNextMatch

 
Malcolm Storey
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSpinner demo program:
http://docs.oracle.com/javase/tutorial/uiswing/examples/components/SpinnerDemoProject/src/components/SpinnerDemo.java
presents a small dialog including a month Spinner. If you type into the month Spinner's TextField, it recognizes your typing and sets the month, but only if you get the case right.

Recognizing the text is handled by SpinnerListModel.findNextMatch(String substring), but this is private. (Presumably just an oversight.)

I tried taking my own copy of SpinnerListModel to make the method public (others have done the same, eg http://www.java9.net/code/4295.html), but this isn't recognized by JSpinner as a SpinnerListModel, so editing is disabled.

To get around this, I took my own copy of JSpinner, but this failed with
UIDefaults.getUI() failed: no ComponentUI class for: sun.com.JSpinner[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=]
java.lang.Error at javax.swing.UIDefaults.getUIError(Unknown Source)


Would the solution be to monitor the contents of the TextField and pre-convert the typing into the values in the list?

Grateful for any suggestions.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in using that demo code, what are you trying to achieve?

if it's just a calendar, there are better (free) ones out there.
if you just want a month/year combo it's relatively simple to roll-your-own.

JSpinner, for dates/times, broke around java 1.4 and I don't know if it's ever been fixed.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The case? I suppose you have the months displayed like Jan and Oct? I have a year-and-month version of JSpinner which works just fine (although it's a bit un-intuitive), I use numeric months.

Edit: I tracked down the code, here's the important bits from the constructor:

 
Malcolm Storey
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul and Michael.

It was actually just SpinnerListModel, but formatting is what I needed (although it doesn't handle the general case where the list is coming from a source you don't have control over)

what are you trying to achieve?


Learning exercise. Am evaluating Spinners. That was just a simple example that showed a problem I was hitting elsewhere.

There is a second problem when the Object[] is something more complex than String.

As you type, it recognizes the entry, but on loss of focus the Spinner flips back to the previously selected value. System.out.println shows my Object's toString() method is returning the value that matches what I typed, so it should work?

On the topic of calendars and date-pickers, I'd be interested in your recommendations.

Thanks again,
Malcolm
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JCalendar is popular

http://www.toedter.com/en/jcalendar/
 
Malcolm Storey
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic