Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.programmer Subject: Re: How to prevent typing value into JSpinner? Date: Thu, 16 Jul 2015 09:30:39 -0700 Organization: A noiseless patient Spider Lines: 35 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 16 Jul 2015 16:29:12 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="e4bb2c7dad0e79edbbf184ec68513a50"; logging-data="8925"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18J9QLS0cD4NUQfkcHamqID" User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 In-Reply-To: Cancel-Lock: sha1:ezzKF8fa7Oo1WhGUoA4Zpd9ovpU= Xref: csiph.com comp.lang.java.programmer:32049 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