Tuesday June 12, 2007
Building a Login Screen for a NetBeans Platform Application (Part 3)
I got a great tip from NetBeans Platform application developer Maksim Mednik the other day. Way back on April 26 and April 27, I wrote about the consequences of the resolution of issue 92570. In a nutshell, you can now show a dialog box before an application's main window opens. In other words, that's the spot where a login screen can be shown. Maxim took a next step in this scenario by... implementing the Authentication Framework provided by SwingLabs.
The result is pretty cool. Now, when the application starts, this dialog box is shown after the splash screen has done its thing, but before the application's main window is shown:
Assuming you fill in the correct user name and password, the login screen vanishes and the main window of the application appears. As one would expect. But, what aboout those days when you wake up thinking you're Henry VII, King of England? Well, on those days you can't get very far:
Quick run through for how to set everything up, assuming you already have an application (otherwise there's not much point in having a login screen, is there) together with Maksim's helpful code:
- Create a library wrapper module project for the SwingLabs JAR.
- In the module where your Login screen is going to be, set a dependency on the library wrapper module.
- Use the Module Installer wizard to create stubs for a module installer. (The wizard also adds the correct dependency on the related NetBeans API module and adds a line to the manifest file.)
- Replace the content of the installer with this file.
- Create a new Java class, for the panel. Replace the content with this file.
- Run the application.
Maksim ends his e-mail to me with the words: "It took me a while to figure out how to call exit when dialog is closed. I didn't find any nice way of calling setDefaultCloseOperation and I'm not sure where one can get a result value from DialogDescriptor when notifyLater is called. Any thoughts would be highly appreciated."
If anyone can help with this question, please leave a comment at the end of this blog entry.
Jun 12 2007, 08:29:17 AM PDT Permalink


