Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #32049

Re: How to prevent typing value into JSpinner?

From Knute Johnson <nospam@rabbitbrush.frazmtn.com>
Newsgroups comp.lang.java.programmer
Subject Re: How to prevent typing value into JSpinner?
Date 2015-07-16 09:30 -0700
Organization A noiseless patient Spider
Message-ID <mo8m4n$8mt$1@dont-email.me> (permalink)
References <mo8kva$3d0$1@dont-email.me> <mo8lce$5oj$1@dont-email.me>

Show all headers | View raw


On 7/16/2015 09:17, Eric Sosman wrote:
> On 7/16/2015 12:10 PM, Knute Johnson wrote:
>> Anybody know how to prevent a user from typing a value into a JSpinner
>> but still have it spin?
>
>      According to
>
> http://docs.oracle.com/javase/tutorial/uiswing/components/spinner.html
>
>      "... if you implement a spinner model that does not descend from
>      SpinnerListModel, SpinnerNumberModel, or SpinnerDateModel, then the
>      spinner's default editor is a non-editable instance of
>      JSpinner.DefaultEditor."
>
> So it appears you have a couple of possibilities.  One, you could use a
> custom model, or two, you could set a custom editor (possibly just a
> raw JSpinner.DefaultEditor instance).  Good luck!
>

Thanks for that!

I found an even simpler answer:

((JSpinner.DefaultEditor)spinner.getEditor()).getTextField().setEditable(false);

Not sure how I missed it on the first two passes through the docs but 
JSpinner.DefaultEditor uses a JFormattedTextField as the editor window.

The only risk I see to this approach is if O changes the text field that 
the editor uses for my specific JSpinner.???Editor. Probably a pretty 
low risk.

-- 

Knute Johnson

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

How to prevent typing value into JSpinner? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-16 09:10 -0700
  Re: How to prevent typing value into JSpinner? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-16 12:17 -0400
    Re: How to prevent typing value into JSpinner? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-16 09:30 -0700

csiph-web