Paul Clapham wrote:Hello Hope, welcome to the Ranch!
In addition to Carey's comment (which you didn't answer), I'm wondering why you chose the addNotify() method to set up the paint characteristics for the component. The documentation for that method just says it registers the component with the keyboard manager, which to me doesn't seem like it has anything to do with painting the component. Was there a reason that the initialization code didn't get put into the constructor?
Paul Clapham wrote:I don't know why addNotify() is called for a JMenuItem but not for a JMenuBar, although since addNotify deals with keyboard management perhaps it isn't called for JMenuBar because JMenuBar and keyboards have nothing to do with each other.
So it looks to me like your "addNotify" code is meant to initialize the component to be painted with a particular gradient. Usually initialization code like yours can go in the constructor, so again, why didn't you do that instead of choosing an apparently random method to run it?
There are three kinds of actuaries: those who can count, and those who can't.
Carey Brown wrote:Are you saying that the code in my post (just before your last one) doesn't work?
Two things I find potentially unreliable with your code is the use of addNotify() (I don't know how you'd guarantee that it gets called), and getting the height from prefferedSize (the actual size may vary depending on the calculations in a layout manager).
A third thing is you are not addressing potential resize events.
Don't get me started about those stupid light bulbs. |