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.
The call to setOpaque(true) should be moved up into the constructor; it only needs to be called once. Similarly, the call g.setColor(Color.black) can be moved up above the for loop. It's okay to override the paint method in your JComponent class. For custom drawing in which you do not want/need to draw over child components it's better to override paintComponent
The setBackground call won't do anything in the JComponent unless you use it like this
Even easier is to extend JPanel instead of JComponent. Then you can place the setBackground call in the constructor, omit the setOpaque call and
Joined: Oct 17, 2005
Thanks alot! thats spot on. Thanks for the tips also, theres always room to improve!
subject: setLocationRelativeTo(null) - problems with setBackground