Just a note, Swing doesn't have the notion (like Java FX) to ask "what's the height given xx width.", so this might not be solvable. That it worked in 4.2 can be because of some re-layout thing that exposed other problems. Now, my Professor swears that this code should work.Apparently, he believes that by using Double objects in the Drawing Canvas class, the references to those objects should make it through the Slider Listener class.The problem is that the code provided does not work as expected; the value in the JText Field next to the slider changes, but the change does not propagate to the custom Canvas object.OK, so here is the code I was provided with: If you run that, you'll see that the 'println' statements show that the changes from the JSliders are not making it into the customized canvas object.In general the layout is created using minimum-, preferred- and maximum dimensions of the components along with layout managers.
You may think that layout managers may solve this this issue, but also layout managers depends on the minimum-, preferred-, and maximum dimensions of a components.
Anyway, I did come up with a version that works, but I went about it by changing the Double objects in Drawing Canvas to primatives, then using some ugly code in the Slider Listener to see which JSlider was changing, then updating the value in canvas directly. The class Double is an immutable wrapper so when you write value = Double.value Of(s Value); in Slider Listener, you're making the variable point to a new object but those in Drawing Canvas still point to the old object.
Obviously, this works, but I'd still like to find out the best way to do this. Essentially what I'm looking for is the "right way (tm)" to update these values. One solution is to write your own mutable wrapper for the primitive double: Thanks Ragazzo! I'm one of those programmers that doesn't like to settle for "well, it works, but it's ugly." This is far more clear than the solution I had previously come up with.
The usual way I have solved the problem, is either insert tags into the html code and force the formatting to be fixed, or hard-coding the height.
Both workarounds have significant disadvantages such as breaking the ability to rescale the component.