3

So, i'm making a program that currently just accepts a file that'd been dragged and dropped into it. I'm using a JFrame for the container at the moment, but I dont think that's really important.

I want the window to always be on top when running, so that if you drag any file to the bottom right corner of the screen, the program will handle it. But, at the same time, i want the program to be able to be invisible, and click-through-able, meaning that you can click on anything underneath the jframe, while it's invisible, but still be able to drag a file into the program without having to do anything special.

I've never heard of something like this, but I'm sure it must be possible. How would I do this?

PulsePanda
  • 1,806
  • 10
  • 33
  • 56
  • 1
    What makes you say it is possible. If I open a full screen application and give it focus, I will never be able to drag-and-drop something onto that `JFrame`, transparent or not. – Robin Oct 19 '14 at 11:43
  • well right now, it is always on top. so as long as no one minimizes it, it will always be on top. This doesn't have to be the case with full screen games, but I want it open any time there could be a file drag. The trick really for me is, making behind it clickable. Could i just use a mouse listener, and have java click behind the program for the user? instead of the user being the one to click, java's doing it? – PulsePanda Oct 19 '14 at 11:45
  • 1
    Let's say you can make a full screen transparent `JFrame` and allow clicks to go through it, meaning you are clicking on the application underneath it. That will give focus to that application, and bring it to the front and your `JFrame` to the back – Robin Oct 19 '14 at 11:47
  • with `JFrame.alwaysOnTop(true);`, even if you give focus to another program, the JFrame is still on top, and I'm still able to drag a file into it. All I need is to be able to interact with what's underneath. The Frame is also not full screen, simply a 250x150 square at the bottom right of the screen – PulsePanda Oct 19 '14 at 11:50
  • @PulsePanda do you want a frame that's always on top.and you should able to drag files to it and if you click on the frame it should click underneath ?? – Madhawa Priyashantha Oct 19 '14 at 12:08
  • @getlost yes, that is exactly what I want. Be able to drag a file to the JFrame and have it handle (currently works with just being `alwaysOnTop`), but be able to click on the area beneath the frame as well – PulsePanda Oct 19 '14 at 12:14
  • Have you tried the answer to this question? [Clicking Past a Transparent Frame (Java)][1] [1]: http://stackoverflow.com/questions/12524132/clicking-past-a-transparent-frame-java?rq=1 – Phe0nix Dec 13 '14 at 17:57
  • I have, the problem is that the window wont be transparent, only translucent. I was thinking on having a mouse listener, and just clicking on the screen beneath it using the coordinates, but i've tried various methods of doing this, and none have really worked (the issue is actually getting it to click underneath, setting the location is easy) – PulsePanda Dec 13 '14 at 18:06
  • 2
    *I've never heard of something like this, but I'm sure it must be possible.* I admire your optimism. I think you might be able to do it with native code. (**Note**: I said *admire*, *think* and *might*. Not I have done this and here is how I did it). – Elliott Frisch Dec 15 '14 at 22:57

1 Answers1

2

I made a Splash screen the other day that was click-through-able. You might want to make a completely transparent image using Photoshop or something else. Here is the code:

private BufferedImage splash;

/**
 * Create the frame.
 */
public Splash() {
    this.setUndecorated(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    setSize(500, 500);
    setLocationRelativeTo(null);

    try {
        splash = ImageIO.read(getClass().getResource("/images/transparent.png"));
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Apply a transparent color to the background
    // This is REALLY important, without this, it won't work!
    setBackground(new Color(0, 255, 0, 0));
    getContentPane().setBackground(Color.BLACK);
    add(new JLabel(new ImageIcon(splash)));
    setVisible(true);
}
Sheikh
  • 539
  • 1
  • 7
  • 29