Over a million developers have joined DZone.

How to Create & Import a JavaBean Component in NetBeans IDE (Part 2)

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

In the final installment of this two part tutorial (part 1 here), we look at how to import and use your new JavaBean component in the NetBeans GUI Builder Matisse.

Adding a New JFrame

Once you have created your JavaBean, you are ready to import it into NetBeans. To be able to use it once it is imported however, we first need to create a new JFrame to house the Component in.

For the benefit of this example, in my case I have a project called PDFHelpBean. As shown in the screen shot below, to add a new JFrame to the project, right click on the "Source Packages" and from the resulting pop-up menu select "New" -> "JFrame Form".

New JFrame

NetBeans will now ask you to choose a name for this new Form. In this example it will be called "PDFHelpFrame". Once you have entered the name click "Finish" and NetBeans will generate a new JFrame class.

New JFrame

Importing the JavaBean component

Once you have added a new JFrame, you are ready to add the JavaBean component to the Matisse palette. From the "Tools" menu select "Palette" -> "Swing/AWT Components".

New JFrame

This will bring up a dialog box asking you from where you wish to import your JavaBean. In this case select the "Add from JAR" button.

New JFrame

Next, in the resulting file chooser dialog, navigate to the location where the JAR file containing your JavaBean is stored, and click "Next".

New JFrame

From the list of available components choose your Component and click "Next".

New JFrame

When choosing which category to add the Component to you are free to choose any you like. For the sake of this tutorial however, "Swing Controls" is selected. When you have chosen your category, click "Finish".

New JFrame

When the Palette Manager reappears click "Close".

Adding the JavaBean to Your JFrame

Once you've imported your JavaBean, you should see your component in the Palette. In my case I can see that the PdfHelpPanel component has been added.

New JFrame

You are now ready to add the component to your form. This is done by dragging the JavaBean from the Palette onto your JFrame. As you will see from the screen shot below, once the component has been added to the JFrame, the JavaBean properties will be exposed and available for the end-user to set. In my case (as indicated by the blue arrow) only the fileLocations property is visible

New JFrame

Once the end-user has set any properties they want to, they can run the application. This is done by clicking the green "Run Main Project" button - as indicated by the blue arrow in the screen shot below - in the NetBeans toolbar.

New JFrame

Upon running the application you will see your JavaBean running inside a fully functioning application. In my case PDF Help is shown in the screen shot below.

New JFrame

And thats all there is to it.  We hope you have found the tutorial useful.  You can see our finished PDFHelp JavaBean application at http://www.idrsolutions.com/help.php.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}