• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to disable JSpinner beeping  RSS feed

 
Paviel Stanislav
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When invalid input is entered into the JSpinner, a beep is played, and I can't figure out how to disable it.

I'm using a number spinner with invalid input not being allowed to be typed in, like so:

 
Rob Camick
Ranch Foreman
Posts: 2821
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSpinner.NumberEditor uses a JFormattedTextField as the editor.

The JFormattedTextField invokes the following code when an error is found:



So if you don't want the default behaviour then you would need to:

1) extend JFormattedText field to override the invalidEdit(...) method
2) create a custom editor for the JSpinner that uses the above JFormattedTextField.

If you want to know how to create a custom editor then look at the source code of the JSpinner class and copy the NumericEditor code.
 
Paviel Stanislav
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:So if you don't want the default behaviour then you would need to:

1) extend JFormattedText field to override the invalidEdit(...) method
2) create a custom editor for the JSpinner that uses the above JFormattedTextField.

If you want to know how to create a custom editor then look at the source code of the JSpinner class and copy the NumericEditor code.

Correct me if I'm wrong, but seeing as there is no setter method for the JFormattedTextField used by the spinner and it is a local variable, there is no way to to replace it with a custom text field.

Is there another way to stop beeping? I've tried editing the beepAction and insertContentAction Map but couldn't get that to work.
 
Rob Camick
Ranch Foreman
Posts: 2821
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paviel Stanislav wrote:Correct me if I'm wrong, but seeing as there is no setter method for the JFormattedTextField used by the spinner and it is a local variable, there is no way to to replace it with a custom text field.


And that is why I suggested you need to create a custom editor so you can override all of that code.

In other words there is no easy solution so you need to decide how much effort you want to do to override the default behaviour of the spinner editor.
 
Dave Tolls
Ranch Foreman
Posts: 3001
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Couldn't you create your own LandF wrapper and override that feedback method to do nothing?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!