wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes setting a formatter for Jspinner to replace a '.' with '-'. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "setting a formatter for Jspinner to replace a Watch "setting a formatter for Jspinner to replace a New topic
Author

setting a formatter for Jspinner to replace a '.' with '-'.

anita Py
Greenhorn

Joined: Apr 19, 2010
Posts: 3
Hi,
I am facing a problem w.r.t JSpinner..
I need to populate the spinner with double values and then based on a boolean value need to show the double value as either with a dot seperating the decimals or with a dash.
Here is an example::
assume the boolean value controlling :: isDash

input value is 1.56
if(isDash){
setSpinner with value as 1-56
}else{
setSpinner with value as 1.56
}

The problem is that inside the spinner is a JFormattedTextField and it resets any formatting changes done from the code ...
Somebody please help me regarding this...

Also if anybody has the source code for PointSpinner, please do share it...
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you might have to get the spinner's UI and install your own listeners to the next/previous buttons,
to increment/decrement a counter, then split the counter into numerator/denominator and set the
editor's text as numerator + (. or -) +denominator

just did a quick test, basics work OK, but it'd need a fair bit of error handling, and many L&F's
these days don't allow access to the UI's

hopefully there's an easier way
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting a formatter for Jspinner to replace a '.' with '-'.
 
Similar Threads
Interdepenent JSpinners problem
2 JSpinners has my head spinning!
JSpinner
Which Swing component to use ?
Please help with a spinner