DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > How to Create & Import a JavaBean Component in NetBeans IDE (Part 2)

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

Mark Stephens user avatar by
Mark Stephens
·
Nov. 05, 08 · Java Zone · Interview
Like (0)
Save
Tweet
21.01K Views

Join the DZone community and get the full member experience.

Join For Free

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.

NetBeans Integrated development environment

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Design a CRUD Web Service for Inheritable Entity
  • Comparing Distributed Databases
  • Instancio: Test Data Generator for Java (Part 2)
  • Autowiring in Spring

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo