Background image in a JDesktopPane

Posted on 2004-11-29
Last Modified: 2012-06-21
Probably, this question has been asked: How do I add a background image to a JDesktopPane. I have already atttempted the following:

      ImageIcon waterMark = ImageLoader.loadIcon("PTSWatermark.gif");
      if (waterMark != null) {
       System.out.println("**** setting the DeskTop with PTS water mark ****");
       JLabel l = new JLabel(waterMark);
       deskTop.add(l, JLayeredPane.FRAME_CONTENT_LAYER);
       deskTop.setBackground(new Color(0x99, 0xCC, 0xCC));
      } else {
        System.err.println("**** PTSWatermark.gif could not be found ****");

where ImageLoader.loadIcon() simply loads the image.  From the println statements, I know that the ImageIcon object is not null.  Can any one help?  

Thanks in advance.
Question by:mwalker
    LVL 24

    Accepted Solution

    A component with a custom background should paint that background first,
    and overwrite it than by all contained components.
    The only way to do so (at present) is to derive your own component (your case: JDesktopPane)
    acting as, but having this overridden 'paintComponent':

    public class MyDesktopPane extends JDesktopPane
      public void paintComponent( Graphics g )
        g.drawImage(background, 0, 0, this);   // background being the image!
        super.paintComponent( g ) ;                // painting everything else.
    LVL 37

    Expert Comment

    How do I display an image in the background of a Swing component?
    LVL 37

    Expert Comment

    Proposal: split
    LVL 37

    Expert Comment

    OK :°)
    Just wonder why it took so long ;°)
    LVL 24

    Expert Comment

    It's cold, all fluids are thicker .....


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now