Over the years, I’ve used GlassPanes quite frequently to provide “unobtrusive” feedback about application events during development and testing. Typically, the pattern that I use is that I have a JPanel that will listen for some kind of event to occur. Once the event occurs, a message is created and displayed as a glasspane (using transparency) over the main frame and kept there for a few seconds. The thing I like with using a GlassPane as opposed to a popup dialog box is that I can continue to use tha application while the message is displayed, and it doesn’t require interaction (i.e. a click) to dismiss the message.
I’ve bundled up two samples of how to do this. The first example notifies the user about the coordinates of a JFrame after it has been moved. The second example notifies the user about the size of the JFrame after it has been resized.
Here is what you see after you move the JFrame in example 1:

The position of the window will stay visible for 3 seconds, after which it will be removed.
The resize example looks very similar, except after the JFrame is resized, you see the size of the JFrame in the GlassPane:

I’ve created WebStartable versions of both examples, as well as making the source code and a test applications available.
Move Example
- Run the example with webstart
- Download the source code to the GlassPane implementation
- Download the source code to the test application
Resize Example
June 10th, 2005 at 1:01 pm
Nice idea.
June 10th, 2005 at 1:08 pm
Very nice stuff! We’ve featured you today on javadesktop.org. (We especially appreciate that you included .jnlp links.)
June 10th, 2005 at 4:19 pm
Looks cool. How about adding a fade-in and fade-out effect?
June 10th, 2005 at 7:50 pm
Funny, I just published a small blog entry about MacOSX notifications, and I just love the “Bezel” interface (which you seem to mimic in your GlassPane demo !
http://jroller.com/page/danielweck/?anchor=applescript_growl_notifications_quicksilver
Keep up the good work !
June 10th, 2005 at 7:56 pm
I tried the ‘resize’ demo, and I love how the translucent message shrinks to adapt ‘intelligently’ to the available window area !
I would recommend the following easy enhancements:
- Make the black background darker (less transparent)
- Drop a shadow of the text in darker shade than the background, to improve readibility
(The screenshot in my blog demonstrates that. See previous comment above)
June 11th, 2005 at 5:00 am
Yes, very nice. I think I try that on my own fun project.
And a fade effect would be really nice, too. I keep coming back to look for your next posts.
June 20th, 2005 at 5:23 pm
Really liked the demos and so tried combining the resize and move demos into one for my own app. It works ok, but one thing that annoys me is that the feedback is displayed when the frame is loaded. This is obviously due to the monitoring of the resizing, as it doesn’t occur with the ‘move’ demo.
I was wondering therefore if anyone had any suggestions on how to prevent the feedback being displayed on load - and only on true user resizes.
Many thanks
June 20th, 2005 at 10:09 pm
It shouldn’t be too hard to combine them and supress the feedback until after the screen is loaded. I’ll add it to my to-do list for this week to figure out how to do it.
June 21st, 2005 at 11:30 am
Indeed - the combining of the move and resize examples was relatively trivial. However, I don’t know where to begin when it comes to surpressing the response until the screen is loaded. I guess I’m still too new to Swing.
It’s not a big deal I suppose because they are only bells and whilstles. But since I’m happy that my app works and is decent from a usability point of view, I thought I’d add a few b&w’s just to show the Java-detractors a half-decent looking Java-app.
I’ll keep my eyes on this blog incase you get chance to resolve this issue
Cheers