This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Hi folks -
I'm pretty new to this, so I don't mind if you explain it to me as if I'm four years old ;)
I'm trying to extend (I think that's the right term) JSlider so I can have multiple sliders in the container, each tracking its own value and each having its own name and tooltip.
When I call the class to add to the container, I get a slider, but it ignores the class information (no ToolTipText, no tick spacing, et cetera).
One of the things I notice is that you're extending JSlider, so mySlider IS-A JSlider. There's no need to create a JSlider in the constructor (one already exists - the one you're creating). Rather you should call the JSlider constructor using "super( ...JSlider constructor arguments... );" then use the "this" keyword to set the properties directly, so "this.setName(..)" or just setName(..) like any method call.
When you don't make a super() call, Java defaults to a no-argument constructor. What I imagine is happening is the following:
Call new mySlider(..); the mySlider constructor calls super() which instantiates a default JSlider.
You create a new JSlider and manipulate its properties.
You then add a JSlider to the existing JSlider (since mySlider IS-A JSlider) control. So now your JSlider components are present in duplicate.
I don't know how Java would render a JSlider with multiple controls...it may just ignore the second slider.
By the way, convention is to capitalize the first letter of any class, so it would be class MySlider rather than class mySlider. There is also a code button for formatting your code rather than displaying inline which makes it easier to read.
Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
Joined: Jan 17, 2012
Wow, thank you! That's got it! Now I'll play around with it a bit more (and likely break it) but I'm making progress!
Thank you so much!