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(); } });
Braj
source share