HoJu
asked on
Keeping the background when painting a JPanel
I've derived a class from JPanel, and I want to draw in it and keep its background black, not gray. Calling
setBackground(Color.black) ;
in the constructor works fine if I don't override paint(). But if I do override paint(), the background color disappears and I can't figure out how to just keep it around and draw over it. Short of simply drawing a big rectangle over the whole panel, what should I be doing to keep the background color?
setBackground(Color.black)
in the constructor works fine if I don't override paint(). But if I do override paint(), the background color disappears and I can't figure out how to just keep it around and draw over it. Short of simply drawing a big rectangle over the whole panel, what should I be doing to keep the background color?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
take a look at it.
the best answer to your question is:
you should never override paint() in Swing components - you should override paintComponent().