Jun 10

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:

An example of what the JFrame looks like after moving it

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:

An example of what the JFrame looks like after resizing it

I’ve created WebStartable versions of both examples, as well as making the source code and a test applications available.

Move Example

Resize Example

9 Responses to “Using a GlassPane to get feedback about a JFrame”

  1. Neil Weber Says:

    Nice idea.

  2. Kathy Walrath Says:

    Very nice stuff! We’ve featured you today on javadesktop.org. (We especially appreciate that you included .jnlp links.)

  3. Dustin Quasar Sacks Says:

    Looks cool. How about adding a fade-in and fade-out effect? ;-)

  4. Daniel WECK Says:

    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 !

  5. Daniel WECK Says:

    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)

  6. Carsten Ringe Says:

    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.

  7. Andy Roberts Says:

    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

  8. Jon Lipsky Says:

    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.

  9. Andy Roberts Says:

    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

Leave a Reply