Search code examples
gxt

How do you set the background-image of a GXT ContentPanel


Seriously, I would think this would be a simple thing, but I can't seem to get it figured out. I have a ContentPanel who's Body I want to set a background for using an Image? How do I do that?

BONUS QUESTION: How do I change that image after the ContentPanel is rendered when a business action is triggered (e.g. user login).


Solution

  • I'm not sure what my problem was. I know I tried this previously, but swore it wasn't rendering they way I wanted it to.

    cp.setBodyStyle("background:black url('http://www.google.com/intl/en/adwords/select/images/samples/leaderboard.jpg') no-repeat top right");
    

    I haven't figured out how to swap it after login yet since I think setBodyStyle can only be called pre-render.

    The solution provided by @AbstractChaos could probably work, but there's a problem using the Image object with that. Might need to incorporate the CssResource.

    UPDATE @see the answer provided by @gonella as well. I no longer use GWT, so I haven't tested it. If that answer gets enough votes, I will change the official answer for this question.