I have a JPanel that has a button in it. The location of the button is irrelevant.
The paint(Graphics g)
code is:
@Override public void paint(Graphics g) { super.paint(g); /* drawing code */ }
If I wanted to fill the entire space of the panel with black rectangle, while also having the button in the panel, the filled in rectangle would simply cover everything up. So rather than having a button and then black all around the button, the entire panel is black.
Is there any way to modify the panel, or the painting procedure, so that the components are drawn on top of the custom painting?
I have tried to put super.paint(g)
at the end of painting, like:
@Override public void paint(Graphics g) { /* drawing code */ super.paint(g); }
... thinking that it would do the custom painting first, and then simply put the components over it. However, if done like that, the custom painting disappears altogether and only the button shows up. That is, only a button and a white (default) background rather than the black rectangle.
Any ideas?
Thanks!
Edit: I want to clarify that the black rectangle is an example. I am aware that I could simply set the background color, but I am trying to ultimately be able to do any custom painting that I would like.