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


Groups > comp.lang.java.programmer > #32047 > unrolled thread

How to prevent typing value into JSpinner?

Started byKnute Johnson <nospam@rabbitbrush.frazmtn.com>
First post2015-07-16 09:10 -0700
Last post2015-07-16 09:30 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  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

#32047 — How to prevent typing value into JSpinner?

FromKnute Johnson <nospam@rabbitbrush.frazmtn.com>
Date2015-07-16 09:10 -0700
SubjectHow to prevent typing value into JSpinner?
Message-ID<mo8kva$3d0$1@dont-email.me>
Anybody know how to prevent a user from typing a value into a JSpinner 
but still have it spin?

Thanks,

-- 

Knute Johnson

[toc] | [next] | [standalone]


#32048

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2015-07-16 12:17 -0400
Message-ID<mo8lce$5oj$1@dont-email.me>
In reply to#32047
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!

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [prev] | [next] | [standalone]


#32049

FromKnute Johnson <nospam@rabbitbrush.frazmtn.com>
Date2015-07-16 09:30 -0700
Message-ID<mo8m4n$8mt$1@dont-email.me>
In reply to#32048
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web