aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Cannot override SpinnerListModel.findNextMatch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Cannot override SpinnerListModel.findNextMatch" Watch "Cannot override SpinnerListModel.findNextMatch" New topic
Author

Cannot override SpinnerListModel.findNextMatch

Malcolm Storey
Ranch Hand

Joined: Nov 09, 2008
Posts: 31
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.


Malcolm

I wouldn't join any Collection with an add() method that would accept me as a parameter
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Nov 09, 2008
Posts: 31
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

Joined: Jun 09, 2003
Posts: 4632
JCalendar is popular

http://www.toedter.com/en/jcalendar/
Malcolm Storey
Ranch Hand

Joined: Nov 09, 2008
Posts: 31
Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot override SpinnerListModel.findNextMatch