So, following from my last post Java Button Width im looking to add some images and set a background color. Ive tried a few things, just everytime i do it. It always gives me errors.
i’ve tried
setBackground(args);
and
img = addImage("image.png");
they dont work for me. Can somebody give me a hand please?
Ok i tried the post made by Disha. And the applet still stays the same color, not black
At the beginning, Please do learn Java Naming Conventions and stick to them.
In order for you to provide a background Color to your
JFrame, since you had added oneJPanelto theCENTER.Hence you cannot get one background color by writing :
Now you have to set the opaque property of the
JPanelto true and set one Background color for the same like :inside your MenuPane Class’s constructor.
Here here is your modified code :
Now in order to add images to your project you can either see this answer for how to add images to your Project in Java and you can get help from this small sample code as well which is as follows :
Do uncomment the lines given below and add your image at the specified location :
If still in doubt, ask any question you might have, I’ll try to provide information, if it is within my bounds 🙂