I have this Swing app I'm working on that has a pair of JSliders and JTextFields that both display & control the value of two numbers. Right now I kind of hacked things together to make it work, intercepting change events and updating the display. However I'm thinking a better way would be to make a model that has the two numbers and somehow link this model to my GUI view. I know how to make a model, but am kind of lost on how I could link that to my GUI view... any suggestions?
update: my model is ready + includes firing property changes. I think I would like to use some kind of data binding approach (e.g. JGoodies Binding) but I am not sure how... JGoodies Binding doesn't support sliders.
edit: also note, when the slider changes position, the text field should change its value; when the text field changes value, the slider should change position; and when the model changes value, both text field + slider should update.
You could define your model and pass it to the view in the constructor.
Have not tried the code, but it could look like that:
To keep the two components synchronized, just have each one's EventListener update the other. Here's an example connecting a JSlider and JSpinner: