How to make a JFrame warning in the taskbar?

I was wondering if Java or JFrame would be able to warn the user when something happened in the program. For example, when a new message appears in Skype, the Skype icon background changes to yellow. "You have received a new message!"

Can I do this in Java?

+7
java alert taskbar
source share
2 answers

At the very least, you can change the JFrame icon by calling the JFrame # setIconImage () method , which looks like a notification, and also change the title as well as necessary.

Create the icon you want to show when there is a notification, and install the icon from the code where you want.


To create a blink effect, you can use two images and share at intervals if the window is minimized using the Swing Timer and stop timer when the window depreciates again.

Learn More How to Use Swing Timers

code example:

private boolean swap; private Timer timer; .... final Image onImage = new ImageIcon(ImageIO.read(new File("resources/1.png"))).getImage(); final Image offImage = new ImageIcon(ImageIO.read(new File("resources/2.png"))).getImage(); // interval of 500 milli-seconds timer = new Timer(500, new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (swap) { setIconImage(onImage); } else { setIconImage(offImage); } swap = !swap; } }); timer.setRepeats(true); // check whether window is in ICONIFIED state or not if (getExtendedState() == JFrame.ICONIFIED) { timer.start(); } addWindowListener(new WindowAdapter() { public void windowDeiconified(WindowEvent e) { // set the icon back to default when window is DEICONIFIED timer.stop(); } }); 
+5
source share

When you call the toFront () or requestFocus () function, the window will flicker the way you want.

The only problem is that it will receive focus, but as long as you do not need it, it is not a problem. (The window will not receive before itself only a request)

0
source share

All Articles