setBackground not working - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

setBackground not working

teahouteahou Posts: 2Member
Hi all. I am just learning Java, and i am trying to go some graphics, but the background color is not showing up, regardless of the color i try. Please see my attached code and let me know any ideas as to why the pictures shows no bacground color.



  • krishbalodakrishbaloda Posts: 45Member
    I think u can't use setBackground(Color c) method while working with Graphics. U can only Use setColor(Color c) method.Coz setBackground(Color c) is a swings method.
  • krishbalodakrishbaloda Posts: 45Member
    This post has been deleted.
  • MiggityMikeMiggityMike Posts: 17Member
    You need to use setColor method. I would just fill in the background with the fill rectangle method(just set the coordinates to the full scale of your picture, this will fill your image with blue then you can place all of your shapes over top of it.

    public void paint(Graphics g) {
    g.fillRect(int x, int y, int width, int height);
Sign In or Register to comment.