0

How to create a notification app icon badge in JavaFX's taskbar icon? Just like Teams or Slack that has a badge on their icon when a notification comes. Like this image:

enter image description here

c0der
  • 18,467
  • 6
  • 33
  • 65
Newbie Coder
  • 141
  • 1
  • 11
  • IntelliJ offers a feature to add the programs icon image on building it, File -> Project Structure -> Artifacts + JavaFX – Joe Jul 01 '19 at 05:04
  • 1
    https://stackoverflow.com/questions/20237050/how-to-change-default-java-logo-exe-icon-on-the-taskbar-in-javafx – Kenneth Clark Jul 01 '19 at 05:20
  • No I mean, like this one https://d2slcw3kip6qmk.cloudfront.net/marketing/pages/chart/slack/notification-icon.png – Newbie Coder Jul 01 '19 at 05:57

1 Answers1

4

There is no specific way to define icons with badges for JavaFX. However, you can change the icon of your application based on whether you have notifications or not:

// define two (or more) different icons
Image iconWithNoNotifications = new Image(this.getClass().getResourceAsStream("app_icon.png"));
Image iconWithNotifications = new Image(this.getClass().getResourceAsStream("app_icon_with_notification.png"));

// change the icon when the notifications count changes
primaryStage.getIcons().add(nNotifications == 0 ? iconWithNoNotifications : iconWithNotifications);
Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36