I don't think there's a platform independent way of doing this. You will have to take a look at the platform-specific API calls and implement them via JNI or JNA.
For Windows, here's a snippet from one of my own applications:
public static void flashWindow(final Shell shell, boolean flashTray,
boolean flashWindow) {
try {
if (isActiveWindow(shell)) {
flashWindow = false;
flashTray = false;
}
User32 lib = (User32) getLibrary("user32", User32.class);
User32.FLASHWINFO flash = new User32.FLASHWINFO();
flash.hWnd = new W32API.HANDLE(new W32API.UINT_PTR(shell.handle)
.toPointer());
flash.uCount = 2;
flash.dwTimeout = 1000;
if (flashTray || flashWindow) {
flash.dwFlags = (flashTray ? User32.FLASHW_TRAY : 0)
| (flashWindow ? User32.FLASHW_CAPTION : 0);
} else {
flash.dwFlags = User32.FLASHW_STOP;
}
flash.cbSize = flash.size();
if (lib.FlashWindowEx(flash) && !flashWindow) {
final FocusListener focusListener = new FocusListener() {
public void focusGained(FocusEvent arg0) {
flashWindow(shell, false, false);
shell.removeFocusListener(this);
}
public void focusLost(FocusEvent arg0) {
}
};
shell.addFocusListener(focusListener);
}
} catch (UnsatisfiedLinkError e) {
}
}
Here's a simplified version of getLibrary()
:
protected static StdCallLibrary getLibrary(String libraryName,
Class<?> interfaceClass) throws UnsatisfiedLinkError {
try {
StdCallLibrary lib = (StdCallLibrary) Native.loadLibrary(libraryName,
interfaceClass);
return lib;
} catch (UnsatisfiedLinkError e) {
Logger.out.error("Could not load " + libraryName + " library.");
throw e;
}
}
Take care to dispose()
the library when you're done with it.