Skip to main content

Flashing Windows XP taskbar

12 replies [Last post]
mattjive
Offline
Joined: 2003-06-16
Points: 0

Hey all,

Many Windows applications now flash in the taskbar when the user should take some action with the window. For example, this is very common with instant messaging applications. When a new message comes in, the window starts flashing until it gets focus. As far as I can tell, there isn't a way to duplicate this behavior using just Swing with no native code. Does anyone know of a workaround? Or, are there any JNI libs for duplicating this behavior? Two approaches sort of come close that I've found so far:

1) Change the frame icon on a timer to make it flash. However, this doesn't change the entire taskbar button so it looks a bit strange.
2) Requesting window focus seems to sort of work, but it's the wrong behavior in general since the window *will* get focus over all the other Java windows you have open instead of just flashing. This is not what you want with an IM application (for example, if you have many IM windows open).

Many thanks!

-Matt

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
scheide
Offline
Joined: 2004-06-02
Points: 0

When the company I work migrated from NT to Win2K we noticed our apps behaving differently because 2K and XP do this flashing in the taskbar instead of bringing the app to the foreground.

Some research indicated we could get could NT-type behavior by manipulating the registry settings under My Computer\HKEY_CURRENT_USER\Control Panel\Desktop for ForegroundFlashCount and ForegoundLockTimeout (both to zero). Same would have to be done under HKEY_USERS as well.

Anyway, this doesn't address your specific question, but does give a hint of an additional area to keep in mind for those researching how to "fix" AWT.

mattjive
Offline
Joined: 2003-06-16
Points: 0

I'm happy report that we've finally found a good solution to this issue. There is an excellent product called JNIWrapper (with their Winpack extension) at http://www.jniwrapper.com. In fact, they implemented the flashing feature in their library within days of us requesting it!

I'd love to see a standard AWT solution to this issue, but at least there is native code that can be used for now.

Regards,
Matt

P.S. -- Winpack also has several other features that are very helpful to Swing apps under Windows:

* Ability to set icons on frames that use a small image and large image so that frame icons under Windows don't look crappy.
* System tray integration.
* Many other features...

Leif Samuelsson
Offline
Joined: 2006-02-17
Points: 0

Hi Matt,

This is an interesting desktop integration issue. Can I ask you to file an
RFE on the JDC?

http://java.sun.com/webapps/bugreport/

Cheers,

/Leif

mattjive
Offline
Joined: 2003-06-16
Points: 0

Leif,

Yep, I will do that. However, I know that any official solution will take at least several years to come out. :) So, if anyone knows a JNI fix, that would be greatly appreciated.

Regards,
Matt

zander
Offline
Joined: 2003-06-13
Points: 0

I'm wondering what _exactly_ you mean with:

> but it's the wrong behavior in general since the window *will* get focus over all the other Java
> windows you have open instead of just flashing. This is not what you want with an IM
> application (for example, if you have many IM windows open).

Does the window get focus right away? Always, even if iconified?
Does the window take away focus from dialogs (maybe even modal ones).

Since I don't have WIndows, I'm wondering where this is going wrong, your explenation left me in the dark.

mattjive
Offline
Joined: 2003-06-16
Points: 0

zander,

I apologize for not being clearer. In Windows, an application can flash the taskbar without requesting focus as a way of notifying the user that the application needs attention. In addition, Windows that request focus will also flash as needing attention (they don't actually take focus, I believe). So, a sort of workaround in Java is to just have a JFrame request focus, which will indeed make the taskbar button flash as desired. However, requesting focus can be a bad thing for many applications. I'll use an IM application as an example -- in that case, you don't want to request focus in an individual IM window, especially if you have many IM windows open at once, since the focus between those windows will switch every time a new message comes in. So, instead of requesting focus (which has the side effect of making the taskbar flash), I'm looking for an API that makes the taskbar flash without requesting focus.

Thanks,
Matt

Leif Samuelsson
Offline
Joined: 2006-02-17
Points: 0

Matt, do you know what the Windows API is to flash the taskbar without requesting focus?

/leif

mattjive
Offline
Joined: 2003-06-16
Points: 0
Leif Samuelsson
Offline
Joined: 2006-02-17
Points: 0

It seems to me that this would be a desired feature in java.awt.Window. I'll send an email to the AWT group to see what they have to say.

/Leif

davetron5000
Offline
Joined: 2003-06-10
Points: 0

OS X has this behavior as well with the icon in the dock bouncing up and down. Seems like it should be a part of JFrame or java.awt.Window as the other person suggested. Or, better yet, perhaps it should just be something that happens whenever your application opens a new window if it doesn't have the focus. Usually, you are flashing the task bar because you've opened up some modal dialog and want the user to make a decision or acknowledge it....

mattjive
Offline
Joined: 2003-06-16
Points: 0

> OS X has this behavior as well with the icon in the
> dock bouncing up and down. Seems like it should be a
> part of JFrame or java.awt.Window as the other person
> suggested. Or, better yet, perhaps it should just be
> something that happens whenever your application
> opens a new window if it doesn't have the focus.
> Usually, you are flashing the task bar because
> you've opened up some modal dialog and want the user
> to make a decision or acknowledge it....

Yep, it makes sense that the feature would live inside of java.awt.Window and not Swing. However, what happens when a new window opens should be up to the OS. I think the general flashing taskbar/application trying to notify user issue is different.

Regards,
Matt

Leif Samuelsson
Offline
Joined: 2006-02-17
Points: 0

This is not exactly what you're asking for, but just for fun you could play with the window's icon and title. You'll need two icon images for this. I used the coffee cup (16x16) and a negative version of it.
[code]
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Flasher extends JFrame implements ActionListener {
private Image cup, cupNeg;
private static final String title = "Flasher";

public Flasher() {
super(title);

cup = new ImageIcon("cup.png").getImage();
cupNeg = new ImageIcon("cupneg.png").getImage();
setIconImage(cup);

setBounds(100, 100, 100, 100);
setVisible(true);
new Timer(200, this).start();
}

public void actionPerformed(ActionEvent evt) {
if (getIconImage() == cup) {
setIconImage(cupNeg);
setTitle("! ! ! !");
} else {
setIconImage(cup);
setTitle(title);
}
}

public static void main(String[] args) {
new Flasher();
}
}
[/code]
Cheers,

/Leif