Please choose a menu option

Part 3 - Adding the PdfHelpPanel component onto a JFrame

The first step to adding the PdfHelpPanel component, is to set the Layout Manager of the JFrame. As shown in the screen shot below, in the "Inspector" window you will see the JFrame. Right-click on it to bring up the context menu, then select "Set Layout" -> "Border Layout".

Set Layout


Finally, we need to set the size of the JFrame. To do this, once again locate the JFrame in the "Inspector" window, however, this time single left click on it. This will bring up the JFrame properties in the "Properties" window. As you will see in the screen shot below, there are four flavors of property a component can have; Properties, Binding, Events and Code. On this occasion select "Code".

From the "Form Size Policy" drop down box select "Generate Resize Code". Then in the "Form Size" property enter "[700, 500]".

Set Size


Adding the PdfHelpPanel JavaBean

Once you have setup the JFrame, locate the PdfHelpPanel JavaBean in the component palette. In this example it is stored in the "Swing Controls" section of the palette, but it will reside wherever you told it to when you imported in.

Select Component


Select the PdfHelpPanel component from the palette and drag and drop it across onto the form.

Add Component


Now that the PdfHelpPanel has been added to the form, we need to add some files to the File List so the user has some PDF documents to search through. This is done through a property accessible through the Matisse Properties panel. The blue arrow in the screen shot below indicates which property to use - it is the fileLocations property. Click on the "..." button as indicated by the arrow to set the property.

Choose Properties


The property takes an array of type String, each String indicating the individual location of each PDF document. Four types of file location are permitted, they are: -

  • An absolute file path of a local location on disk
  • A directory path which will be scanned recursively, adding all PDFs found to the file list
  • A URL
  • A classpath location

Examples are: -

  • C:/file.pdf
  • C:/PdfFiles/
  • http://www.jpedal.org/jpedal.pdf
  • jar:/com/idrsolutions/pdf/pdfhelp/res/jpedal.pdf

Matisse will display a customized dialog box allowing you to pass any number of String paths into the method. As shown in the screen shot below, in this example three location types are used: an absolute file path, a URL, and a classpath location. When you have added all the desired PDF locations, click the "OK" button.

Add Files


We can now see that the PdfHelpPanel has updated its File List to include the three files added. To run the application click the green "Run Main Project" button - as indicated by the blue arrow in the screen shot below - in the NetBeans toolbar.

New Project


The first time you run the application NetBeans will tell you that the PDFHelpBean project does not have a Main Class, and it will ask you to choose one from a list. There will only be one item in the list - the PDFHelpFrame. Select it and click "OK".

New Project


Upon running the application you will see PDF Help as shown in the screen shot below. You can either customize this application further in Matisse to fit your specific needs, or you could even put this example directly into your end user applications, thereby providing the users of your software with 100% pure Java, online, searchable help.

New Project


If you don't wish to use PDF Help as a JavaBean component, the PdfHelpPanel extends the standard JPanel so you can very easily add it to your existing applications through standard Swing code. A simple sample application describing this type of usage is provided here.

<-- Part 2

PDF viewer