I have a desktop based UI application written in Java SWT running on windows.
I want to add a button on the UI screen whose behaviour should be similar to the badges on an iphone or facebook notifications as shown in the images below.
The number on the badge will be dynamic and will increase or decrease based on the number of pending notifications.
How can I implement something similar in SWT/AWT?
IOS Badge:
Facebook Notification:
![]()
I've implemented something like that recently. You can simply paint a custom image with
GC, and the overlay on your desired icon.I'm including my helper class here. It's not the cleanest code (a lot of stuff is hardcoded), but you'll get the point. The notification bubble resizes itself depending on the number of notifications (max 999).
How to use (Remember to cache and/or dispose your images!):