Wednesday Sep 30, 2009

NetBeans tip: Notifications using the Dialogs API

The standard code used to display a dialog in NetBeans is:

DialogDescriptor dd = new DialogDescriptor(new UIPanel(), "UI Panel" ) ;
Dialog dlg = DialogDisplayer.getDefault().createDialog(dd);
dlg.setVisible(true);

This uses the DialogDescriptor and DialogDisplayer classes from the Dialogs API. You end up a dialog which looks like the image below.

Standard UI Panel

However, what if you want to display some notification messages to the user? NotificationLineSupport to the rescue. Just create a notification line (code highlighted below) and add your message.

DialogDescriptor dd = new DialogDescriptor(new UIPanel(), "UI Panel" ) ;
NotificationLineSupport supp = dd.createNotificationLineSupport();
Dialog dlg = DialogDisplayer.getDefault().createDialog(dd);
supp.setInformationMessage("Sample Information Message" ) ;
dlg.setVisible(true);

The result is a dialog like the one shown below:

UI Panel with notifications

You can show informational messages, error messages and warning messages. However, displaying an error or a warning message does not disable the OK button. For that you will have to call the setValid() method.

About

Rohan Ranade's musings on anything and everything.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today