Mike said:
yes, in this case they do not need to be changed dynamically, but do need to
be changed anytime the bean is droppen onto a form (ie design time only -
not run time). Okay.
You seem to have a misunderstanding about the meaning and requirements
of "design time" with respect to beans. If properties need to be set a
design time (i.e. in a GUI builder or the like) then they cannot be
read-only. Bean-aware tools do not recompile your beans, nor do they
perform any kind of magic that you do not write your own code for. Such
tools instantiate your bean and set properties on the instance, using
the mutator methods that you make accessible. Thus design time _is_
runtime for the beans, albeit not for the application you are assembling.
Okay, that is where I have the setXXX methods.
Okay, obviously I am missing something really basic here
See above.
In addition, you seem to be missing (at least some of) the MVC
implementation that Swing employs. The JSpinner class and your custom
subclass each serve in both the view and controller roles, and the
component is completed by a separate model class. To cause the
appearance or behavior of the composite to change, you must use the
controller to change the model, with the result then reflected by the
view. (Classic MVC / model 2, except for the controller and view being
melded together.) What you are doing instead is giving the controller
its own state, and creating properties that modify that state -- but
that state isn't otherwise used anywhere.
The methods I have are:
public void setInit(int i){
init = i;
}
public void setMin(int mn){
min = mn;
}
public void setMax(int mx){
max = mx;
}
public void setStep(int s){
step = s;
}
I thought that by changing the values for init,min,max,step in the property
sheet would send the values to those methods (above) which would then supply
them to the model constructor when compiling - this is not working, so is
there something that I have to do in addition, to get the values I supply in
the property sheet into the variables that are used in the constructor ?
Compilation is already long since done when you are setting properties
on the bean via Forte. The model is constructed with the values you
pass to its constructor in your own code, not any others.
In addition, there is a value int he property sheet valled "value" which is
set to 0 and is not editable - I don't know if this has anything to do with
it.
That may be because the type of the value property is Object.
Unfortunately, JSpinner is more complicated than some Swing widgets in
that it uses a child JComponent to display and potentially change the
value property. You might or might not be able to ignore that. You
might be able to create a related, int-typed property ("intValue", for
instance) that was tied together at the back end (setting it might just
create a new Integer and pass it to setValue; reading it might then do
the reverse) and could be manipulated by Forte.
Then for the other properties it looks like you want something of the form:
public void setMin(int mn) {
MySpinnerModel mod = (MySpinnerModel) this.getModel();
mod.setMinimum(mn);
}
And likewise for the other real properties. (As I understand it, init
is not a real property, it is an initial value for the value property.)
For robustness you should also override setModel:
public void setModel(SpinnerModel model) {
if (!(model instanceof MySpinnerModel)) {
throw new IllegalArgumentException("incompatible model class");
} else {
super.setModel(model);
}
}
Otherwise you could end up with your subclass having a model of the
wrong type.
Good Luck,
John Bollinger
(e-mail address removed)