Recently at IDR solutions we were busy working on adding new features to our NetBeans JavaFX PDF viewer plugin making it even cooler. After adding 3 menu options to our plugin we wanted to add a notification that will be displayed from NetBeans and not from the application itself. To do so we used Dialogs API that comes with the NetBeans platform, therefore in this article I will show you how we added NotifyDescriptor.Message Dialog API and the other Dialogs that you can use.
Dialogs API provides alternative to the use of JDialog or JOptionPane and they are generated from NetBeans and not from your application. They are easy to use and altered.
NotifyDescriptor are the most common dialogs of standard dialogs and here there are:
NotifyDescriptor.Message – displays dialog box containing the message.
NotifyDescriptor.Message msg = new NotifyDescriptor.Message("This is a message "); DialogDisplayer.getDefault().notify(msg);
NotifyDescriptor.InputLine – requesting input from the user.
You have to type the text that will be displayed and the title.
NotifyDescriptor.InputLine msg = new NotifyDescriptor.InputLine("Password ","Password required"); DialogDisplayer.getDefault().notify(msg);
NotifyDescriptor.Confirmation – displays question for the user.
NotifyDescriptor.Confirmation msg = new NotifyDescriptor.Confirmation("Do you want to continue? "); DialogDisplayer.getDefault().notify(msg);
NotifyDescriptor.Exception – informing user.
NotifyDescriptor msg = new NotifyDescriptor.Exception(new Exception("This is Exception")); DialogDisplayer.getDefault().notify(msg);
Apart from Dialogs API’s, NetBeans also offers Progress API that we often use in our applications which is very easy to implement. Below is how it is done:
ProgressHandle ph = ProgressHandleFactory.createSystemHandle("The Progress"); ph.start(100);
Remember to add a module dependency on Progress API:
Right click on your project > chose properties > select libraries from the left panel >click Add. In the module dependency dialog, in the filter type: Progress API and click OK.
Hopfully you have found this information useful.
This post is part of our “NetBeans article Index” series. In these articles, we aim to explore NetBeans in different ways, from useful hint and tips, to our how-to’s, experiences and usage of the NetBeans IDE.