image with transparent background on desktop?

what is the best way to draw an image on the desktop without anything around it, i just want an image on my desktop i need to know if this is easyly done?

thats without any JPanel visible behind it or any top menu (u know the windows minimize maximaise thing)

thanks

Frame.setUndecorated(true);

I think Window is undecorated always. If you need something that is not square, Java does not support it. You can fake it a little using java.awt.Robot to capture the screen and blend you image with was behind your window.

I had a little demo around here somewhere that would let you drag a circle around the desktop that way… I keep losing track of it though.

thanks for your reply just what i needed, however if you do find that demo please do let me know

thx

SkinRegion may be what you’re looking for.

thx for your reply but i think the skinregion is a bit much, its not really what i’m after, i’m just trying to get an animated gif to appear on the screen, with out any boarders or frames, just the pic, a bit like those screen mate applications.

thanks

dont those screen mate apps only show up when the application is focused?

i think anyway, that to get non rect window you have to use jni or something. theres lots of stuff like that around here, so u should beable to find more about how to do that by searching thru the forum :smiley:

Ok… I couldn’t find what I did before, so I just whipped this up… I notice that it sucks on the Mac because of the shadows around the window. I haven’t tested it on Linux or Windows but it’s enough to give you the idea anyway. It look like JNI is really the way to do this right though.

Run this and drag the red circle around the screen…


import java.awt.AWTException;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.SwingUtilities;

/*
 * Created on Mar 4, 2004
 *
 * @author scottpalmer
 *
 */
public class ShapeWindow extends Frame implements MouseMotionListener
{
    public ShapeWindow() throws AWTException {
        setUndecorated(true);
        setBounds(rect);
        r = new Robot();
        behindImg = r.createScreenCapture(rect);
        compositeImg = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(64,64);
        addMouseMotionListener(this);
    }

    public static void main(String[] args) throws AWTException {
        ShapeWindow sw = new ShapeWindow();
        sw.setVisible(true);
    }

    public void paint(Graphics g) {
        Graphics gc = compositeImg.getGraphics();
        gc.drawImage(behindImg,0,0,64,64,null);
        gc.setColor(Color.RED);
        gc.drawArc(0,0,64,64,0,360);
        gc.dispose();
        g.drawImage(compositeImg,0,0,getWidth(),getHeight(),null);
    }
    
    private void computeNewImage( Point p ) {
        int dx = -p.x;
        int dy = -p.y;
        SwingUtilities.convertPointToScreen(p,this);
        rect.x = p.x;
        rect.y = p.y;
        Image img = r.createScreenCapture(rect);
        
        // draw old background into this image.
        img.getGraphics().drawImage(behindImg,dx,dy,64,64,null);
        behindImg = img;
    }
    
    // Mouse listener
    public void mouseDragged(MouseEvent e) {
        Point p = e.getPoint();
        computeNewImage( p );
        repaint();
        setLocation( p );
    }

    public void mouseMoved(MouseEvent e) {
    }
    
    Rectangle rect = new Rectangle(16,16,64,64);
    Robot r;
    Image behindImg;
    Image compositeImg;
}

that code is excellent just what i was looking for, thank you very much. :smiley:

oh by the way i maybe a little stupid but i can’t seem to figure out a way to make the graphics continue updating by them selves, i know the repaint() command does this but how would i incoporate it into this code so it automatically updates just like it does when u drag it around.

thanks

Use a swing timer.

thanks for all the help, after a little try, i’ve managed to come up with

http://myweb.tiscali.co.uk/solat/test.jar

but its not working how i want it to or how it should. i’m doing something very wrong. the problem is that the back ground is not working properly on some places, and i’m getting shadows, like blur copys of the orginal pic.

i’m trying to create a sonic character that runs around on your screen.
so far when you start it appears in the top left hand of the screen, what i want it to do, is once i drag it the first time. the sonic character should run on the desktop from left to right and back. i’ve managed to do this but its just the background and bluring thats giving me problems, if anyone can have a look at it and see what wrong or fix it, i’d greatly appericate it.

The source code is also in the jar file.