wchargin
wchargin

Reputation: 16037

Invisible window is greedy

I've used Java's translucent and shaped windows in order to create a notification system akin to Growl. Basically, there's an invisible always-on-top window lurking in the right-hand side of your screen, to which notifications are added as they come in. It works as desired.

However, if I try to click a button in another application that lies within the bounds of this invisible window (which is a maximum of 400px wide), the click event goes to my application, which is weird, because it's invisible and doesn't do anything. It really confused me; I thought the other application had frozen.

Is there a way for me to allow other applications to "click-through" my application?

I don't feel a full SSCCE is required here, but here's a fragment of code that may be relevant:

// Set up frame: no border, etc. (undecorated); transparent.
frame.setUndecorated(true);
frame.setAlwaysOnTop(true);
frame.setResizable(false); // on Mac and maybe other platforms, even
                            // undecorated windows can be
                            // resized
AWTUtilities.setWindowOpaque(frame, false);

// Determine and set size and position.
// Height: maximized; width: maximized up to 400px.
Toolkit toolkit = Toolkit.getDefaultToolkit();
Insets insets = toolkit.getScreenInsets(frame
        .getGraphicsConfiguration());
Dimension screenSize = toolkit.getScreenSize();


Dimension availableSpace = new Dimension(screenSize.width - insets.left
        - insets.right, screenSize.height - insets.bottom - insets.top);

frame.setSize(new Dimension(
        400 > availableSpace.width ? availableSpace.width : 400,
        availableSpace.height));
frame.setLocation(screenSize.width - insets.right
        - frame.getSize().width, insets.top);

// Set the content of the frame to the datum holder.
frame.setContentPane(client.createPanel());

Thanks!

Upvotes: 2

Views: 766

Answers (2)

Artur Witek
Artur Witek

Reputation: 119

Note that this issue was introduced in Java7 - Oracle distribution for Mac. For Java6 it works fine on Mac. It also works fine on All windows platforms / java versions.

Maybe there's a chance they will fix this in the further releases ?

Upvotes: 3

David Kroukamp
David Kroukamp

Reputation: 36423

Just because your window is opaque/translucent doesn't mean its not there, hence, it is still receiving the click events within its bounds.

Why not set your window to not be visible when you dont use it, and set is to be visible when a new notification is posted to is by using:

window_instance.setVisible(false);//hides window
window_instance.setVisible(true);//shows window

You might want your window to remain visible for a short period after each new notification is posted to it, simply use a Timer and TimerTask and have a sufficient delay, from within the TimerTasks run() method set the window instance to invisible if its not already.

Also see here for help with Timer's: Using the Timer and TimerTask Classes

Upvotes: 2

Related Questions