I have a JPanel that has a button in it. The location of the button does not matter. Code paint(Graphics g) :
@Override
public void paint (Graphics g) {
super.paint (g);
/ * drawing code * /
}
If I wanted to fill the entire panel space with a black rectangle, and also by clicking the button on the panel, the filled rectangle would simply cover everything. Thus, instead of pressing a button and then black around the button, the entire panel is black.
Is there a way to change the panel or drawing procedure so that the components are drawn on top of the custom painting?
I tried putting super.paint(g) at the end of the picture, for example:
@Override
public void paint (Graphics g) {
/ * drawing code * /
super.paint (g);
}
... thinking that at first it will make a normal picture, and then just place the components above it. However, if everything is done like this, the usual picture disappears altogether, and only the button appears. That is, only the button and the white (default) background, and not the black rectangle.
Any ideas?
Thank you
Edit: I want to clarify that the black rectangle is an example. I know that I could just set the background color, but I try to ultimately make any custom picture that I would like.
source share