Building a Login Screen for a NetBeans Platform Application (Part 1)

Since the resolution of issue 92570, it is possible to show a modal dialog after the appearance of an application's splash screen, but before the appearance of an application's main window. And what would one want to put there? A login screen, of course. With this enhancement, it is possible to integrate some level of authentication into your NetBeans Platform application.

The specific method in question here is DialogDisplayer.notifyLater, which can now also be called before the main window is opened. When called from ModuleInstall.restored, the modal dialog is opened and blocks the main window until the modal dialog is closed. So, to implement this, use the Module Installer wizard, which will create a class that extends ModuleInstall (and adds relevant entries in the project.xml file and manifest file). You get a skeleton restored method for free. Fill out the method as follows:

public void restored() {
   NotifyDescriptor nd = new NotifyDescriptor.Message("Ok");

You will now get a simple modal dialog, after the splash screen, where you must click OK before the main window of the application can open. See further examples in the Javadoc for Class NotifyDescriptor.

However, you can also create your own JPanel and return that in the above code, instead of "Ok". So, here's my new code:

LoginForm form = new LoginForm();
public void restored() {
   NotifyDescriptor nd = new NotifyDescriptor.Confirmation(form,"Login");

And your LoginForm could be anything here. Mine looks like this:

It could be wired up to a database, with logic in the panel for verifying the password. So, the key to all of this is the fact that it is a modal dialog that appears after the splash screen and before the main window. Hurray!

Continue with part 2 of this series...

In other news. What?! Another new domain name in the NetBeans world? Yes. And it is... Check it out! Hilarious adventures (e.g., "Today we’re discovering the hard way why Turkish beer is just not a morning’s best friend...") of two random American dudes from Prague delivering NetBeans IDE to some guy in Palestine who couldn't receive it by mail...


Great news, some people here in Germany were just asking about it.

Posted by Roumen on April 25, 2007 at 11:24 PM PDT #

Great news ! Finally we can get rid of all the login hacks and provide a normal Platform way... I assume this will go into 6.0 no ? Do you know if System.exit() is still needed there or we can use the LifecycleManager's exit method? PS: What's the deal with the netbeans domains ? Are we allowed/encouraged to register them ? I always assumed there is some trademark on the NetBeans name and thus Sun might enforce it.

Posted by Emilian Bold on April 25, 2007 at 11:24 PM PDT #

Hi Roumen, good to hear, hope it helps.

Hi Emilian, yes, this will be part of 6.0. The LifecylceManager's exit method seems fine to use. About the NetBeans domains, is not owned by someone randomly, but by NetBeans itself. About your question whether you'd have trademark issues if you created such domains yourself, I don't know, will try to find out.

Posted by Geertjan on April 26, 2007 at 09:43 PM PDT #

hi Geertjan,

i have other/continue scenario:

after login, there are logout menu

if logout menu clicked,
than logout menu change become login menu
on this state (logout) only help/about and login menu that enable.

how to implement it?

Posted by Agus Suhartono on May 01, 2007 at 11:53 PM PDT #

Where can I find NotifyDescriptor in NetBeans 6.0 Beta 1 ?
Please send me an email.

Posted by Catalin Mincu on September 22, 2007 at 06:39 AM PDT #

Hi im new to netbeans and java I have started a
java desktop application (netbeans 6.5) love this article but how do i get past the first step Module Installer wizard I cant find this in the IDE or do you mean the plugins GUI under tools....


Posted by Pete on July 30, 2008 at 06:37 AM PDT #

Pete, create a new module (not a Java desktop application which is what you seem to have but which has nothing to do with the NetBeans Platform), right-click it, choose New | Other and then in the New File dialog choose Module Development | Module Installer. (Then join the mailing list to join discussions and questions about the NetBeans Platform.)

Posted by Geertjan on July 30, 2008 at 09:14 AM PDT #

I created this module, but it run when i start netbeans.What can I do to add this login window to my application ?

Posted by rafaub on October 14, 2008 at 12:12 AM PDT #

It is good one. but I want to have login form created which should be displayed in taskbar also. what to do for that

Posted by Alok Kumar on March 10, 2010 at 04:05 PM PST #

It's good. I need this one but i want to manage several Action in Menu Bar that can be accessed based on user name and password. My user be particied into some group like admin, manager, customer etc. Admin can access all Action in Menu Bar and all topComponent. manager and customer only can access some Action.
I think it just like setVisible true or false for that Action. in Java Application or Java Desktop Application, it can be done. but i don't know to do this in Netbeans Platform. I use Netbeans 6.8.
Please, help me. Send me an email.
Thank you.

Posted by agusenpai on July 24, 2010 at 09:49 AM PDT #

help ! :) how to disable basic autentication dialog in netbeans rcp?

Posted by dima on April 25, 2011 at 02:31 AM PDT #

Hey could you upload some code? there are stupid rookies like me that we just don't understand WTF to do, I need to see something more basic. I'm sorry, but this tutorial doesn't help me at all, and I really want to know how to do it.


Posted by guest on July 26, 2011 at 12:44 AM PDT #


Thanks a lot for this tutorial. Add some validation against DB and work. My NetBeans Platform Application (7.0) now validate the user ...

how do my app know the logged user ?

Thanks for your help.

Posted by hollmanlp on August 08, 2011 at 03:55 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

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.


« April 2014