Hey Guys i wonder if any one could help me in setting a background image for JDesktopPane
instead of changeing background colors...

i'll be gratefull for Detailed Describtion of any written code

Thank you people in advance.

Create a subclass of JDesktopPane and override paintComponent(Graphics) to draw the image.

i already had an instance of JDesktopPane in my Class which Extends JFrame

JDesktopPane Desktop=new JDesktopPane

the Question here is How to use this instance to set Background image on Desktop

As I already said above, you need to subclass JDesktopPane and override paintComponent()

class ImageDesktopPane extends JDesktopPane {
  public void paintComponent(Graphics g){
    g.drawImage( ... )

i'm Sorry it Doesn't work ...... try make it Simpler if Could

"It doesn't work" is not a description of the difficulties you're having. How can anyone know what it was that you tried? What errors occurred?

Post the code. Post error messages or specific questions.

I'm not going to guess what it was that you did that did not work and I won't just write the code for you.

that's simplier as I ever seen, what do you meaning about this one

import java.awt.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import javax.swing.*;

public class Background extends JPanel {

    private static final long serialVersionUID = 1L;
    private BufferedImage image;
    private Ellipse2D.Double ball;

    protected void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        if (image == null) {
        g2.drawImage(image, 0, 0, this);

    private void initImage() {
        int w = getWidth();
        int h = getHeight();
        int type = BufferedImage.TYPE_INT_RGB;
        image = new BufferedImage(w, h, type);
        Graphics2D g2 = image.createGraphics();
        GradientPaint gradient = new GradientPaint(0, 0, Color.white, w, h, Color.darkGray);
        g2.fillRect(0, 0, w, h);
        int d = Math.min(w, h) / 4; // initialize ball
        ball = new Ellipse2D.Double(w / 3, h / 4, d, d);

    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.getContentPane().add(new Background());
        f.setSize(400, 400);
        f.setLocation(200, 200);

@ Ezzaral,

hmmmm you are right :-), my post can't help for his ....