Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Read-only JSpinner?

843805Feb 8 2007 — edited Apr 26 2008
This may seem a little weird, but bear with me; I think the use case is valid.

I am writing an abstract java.beans.Customizer that makes use of the JGoodies Binding framework, specifically the PresentationModel class. You need not know any details about this class except that it makes working with Java Beans properties very simple and allows many views to reflect changes in a common underlying model (the bean itself).

Users of this Customizer who subclass it typically need to create some kind of Swing widget and bind it to a bean property, like so:
this.bind(this.ageSpinner, "age");
As I hope is clear this means bind the Customizer's bean property "age" to the ageSpinner component, which, for the sake of this question, let's assume is a JSpinner.

Now, it just so happens that getAge() happens to be a computed property (that is, there is no setter).

I would like it to be the case that if someone decides to bind a JSpinner to a read-only property that the spinner would not permit edits of any kind.

I would also like it to be the case, however, that the user could, if they so desired, select text in the JSpinner's editor. This means that jSpinner.setEnabled(false) doesn't cut it.

JSpinner does not support an "editable" property, and its editor already has a read-only JFormatted text field. What I need to do is disable any effect the spinner's buttons may have on its associated JFormattedTextField. What's the best way of doing this?

Thanks,
Laird
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 24 2008
Added on Feb 8 2007
9 comments
836 views