org.openide.awt.NotificationDisplayer

The question of the day comes from Christopher Chak, from Experian ("Experian is a global leader in consumer and business credit reporting and marketing services and a constituent of the United Kingdom's FTSE 100 index, with revenues in excess of US$4 billion. We support clients in more than 65 countries and employ more than 15,500 people in 38 countries."). Christopher writes the following on the dev@openide.netbeans.org mailing list today:
I'm trying to implement a StatusLineElementProvider in my project. I have managed to get an icon to appear within a JPanel on the status bar. My question: how do I implement a popup 'text bubble' when I mouse over the icon, ie. exactly like the 'text bubble' that appears on the update reminder icon for the IDE?

Well, the answer is that there's a new class in NetBeans Platform 6.7:

That's org.openide.awt.NotificationDisplayer. So there's three different constructors. Here's one of them in action:

public void actionPerformed(ActionEvent e) {
    NotificationDisplayer.getDefault().notify("Title 1", icon, "Text 1", new DemoActionListener(), NotificationDisplayer.Priority.HIGH);
}

Some screenshots. First, if there's one notification:

Possibly, there's more, and then you see this:

So, Christopher, forget your StatusLineElementProvider and just use the NotificationDisplayer instead! In one line, you'll get exactly what you're looking for! For previous releases, you might look for this code in the 6.7 sources and copy them into your own application.

 

Comments:

I found the notification API also very useful and easy to use. See
http://wiki.netbeans.org/FitnessViaPostMortem
which will be integrated for 6.8

Posted by Jaroslav Tulach on May 30, 2009 at 05:46 AM PDT #

Hi Geertjan, thanks for the prompt reply and solution! We implemented it like you suggested, but our balloon's come out square-ish. Maybe because its missing some other files? We extracted all notification displayer files to be included in my module, in NB6.5. Any thoughts? Thanks in advance.

Posted by Chris on June 09, 2009 at 11:12 AM PDT #

Don't know. Join the dev@openide.netbeans.org mailing list and ask your question there:
http://openide.netbeans.org/servlets/SummarizeList?listName=dev

Posted by Geertjan on June 14, 2009 at 11:14 PM PDT #

I tried using the NotificationDisplayer but it seems as if the main window simply ignored it. I can write a line using StatusDisplayer, but cannot add an icon. Thoughts??

Posted by Richard on July 21, 2009 at 07:23 AM PDT #

Hi Geertjan,

I think I found 2 bugs/errors:
1. In the NotificationDisplayer javadoc, inside the notify method text ( http://bits.netbeans.org/dev/javadoc/org-openide-awt/org/openide/awt/NotificationDisplayer.html ) it is written: "detailsAction - Action to invoke when user click details text or null.", but that is not correct! If I try to pass null to the method, I receive the following error:"NullPointerException: detailsAction cannot be null.";

2. If I try to use the NotificationDisplayer without selecting the Auto-Update module dependency, then I receive another error, a NullPointerException when trying to load the dismiss icon inside BalloonManager.java. The path for that icon is: "org/netbeans/modules/autoupdate/ui/resources/dismiss_enabled.png";

Where can I file this bugs?

Posted by Anderson on August 04, 2009 at 03:46 AM PDT #

anderson: they're both bugs, please file then in issuezilla against Platform/Other

http://www.netbeans.org/issues/enter_bug.cgi?component=platform

thanks

Posted by stan on August 04, 2009 at 07:26 PM PDT #

Geertjan: We can get the notifications working fine, but we would like to know when the user has "closed" off a notification, so that we can take some action.

The actionListener only gets called when the user selects the link from the displayed notification.

When we looked in the source code, we could only find the SimpleNotificationDisplayer implemented, that simply writes to the status line. where is the code for the version that produces the balloons etc, so that we can override/replace it in our run time ?

Thanks

Martin

Posted by Martin Farmer on May 27, 2010 at 05:36 AM PDT #

Hello Geertjan,

In agreement with Martin that it is somehow not possible of getting informed about the user manually clearing a notification. However, NotificationDisplayerImpl does have methods addProprtyChangeListener and removePropertyChangeListener that inform subscribers about added/removed notifications. Couldn't these be added as abstract methods to the NotificationDisplayer itself?

Also, the Notification class itself doesn't come with a clear(int timeInMillis) method to allow users to time-out Notifications. It only comes with the clear() method that clears a Notification immediately.

Other than that it's quite useful...

Posted by guest on November 13, 2013 at 05:07 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
21
22
23
24
25
26
27
28
29
30
   
       
Today