Swing Hack 7: Let it Snow!
December 22nd, 2003
I've always wanted to make some sort of display that draws outside of a window with images scattered all across the screen. Though previously impossible in Java, I found a way to do it. And since Christmas is coming up I thought I'd use it to make a snowflake display. Here's a cropped screenshot of what it looks like:
Swing Hack 6: Ghost Mouse
December 9th, 2003
I've been playing with Swing a lot lately for my new series of articles. In my research I came across another interesting class java.awt.Robot
. It's a class that can automate the UI, mainly for testing. One particularly cool feature is the mouseMove
function. Once I saw this I got evil ideas. :) Imagine rogue java programs that move the mouse cursor to mystify and befuddle the user. Spelling out hideous horrible messages. Redrum! Redrum!. :)
Swing Hack 5: a magic lens
November 5th, 2003
It's been a while since I've written something, so I thought I'd start out with another Swing Hack. This time I've expanded on the overlay idea of SwingHack 3 by adding sort of a magic lens. In this hack the overlaid information can only be seen when the special lens cursor is over it. To pull this off I've created a custom cursor using a buffer image and set it on the glasspane. The buffer contains a crude set of boxes to define the view area, but you could just as easily use an image of a magnifying lens. Next I've restricted the drawing of the glass pane to only be under the cursor by getting the cursor coordinates from a mouse motion listener and setting a clipping rectangle centered around the cursor. Finally I've added code to print the mouse coordinates as part of the cursor. Run, compile, and you get this: (pretend that you can see the cursor which Windows printscreen thoughtfully removes for you)
Swing Hack 4: The universal right click
October 3rd, 2003
I received an email today asking about my use of the glass pane. It seems this fellow wants to handle right clicks on any component in each screen. A logical request. In most cases your right clicks are not limited to a single component, yet to receive the events required to show popups you have to add a listener to each component! Not enjoyable.
Swing Hack 3: Overlay Graphics
September 26th, 2003
It's Friday so I thought I'd do another Swing hack:
SwingHack: keyboard spinner
August 28th, 2003
While crusing through the AWT/Swing documentation for another project I ran across a method I never knew existed: Toolkit.setLockingKeyState(int keyCode, boolean on)
. It's been there since 1.3 (which is what, 3 years old now) but I never noticed it before. Hmm, I thought. What could I use that for?
Swing Hack: Window Snapping
August 22nd, 2003
While working on another project I came up with a silly idea. How could I force windows to remain completely on screen and to snap to the screen edges? A simple form of window snapping. Since you can receive an event every time the window is moved it's easy to create a Component Listener to do it.