Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Background image in a JDesktopPane

Posted on 2004-11-29
6
Medium Priority
?
1,609 Views
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);
       l.setOpaque(true);
       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.
0
Comment
Question by:mwalker
  • 3
  • 2
5 Comments
 
LVL 24

Accepted Solution

by:
sciuriware earned 500 total points
ID: 12703542
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.
  }
.................
}
<*>
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12706438
How do I display an image in the background of a Swing component? http://www.jguru.com/faq/view.jsp?EID=9691
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12983153
Proposal: split
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12983224
OK :°)
Just wonder why it took so long ;°)
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12985242
It's cold, all fluids are thicker .....


;JOOP!
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses
Course of the Month15 days, 11 hours left to enroll

580 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