I don't think you can do that with pure Java, at least not as you described it. You could use a combination of a MouseListener and the Robot class to get the appearance of something similar though.