Maryland in Europe Logo


How to Install Predefined Templates in NetBeans

by Larry Arnoldy

NetBeans uses templates to assist with creating Java source files. Whenever you create a new Java source file within NetBeans you must choose which template you wish to use. The ones that you will most often use are the Java Class and the Java Main Class templates. There are seven built in Java Class templates. Using the template Empty Java File is equivalent to using no template.

Built in Templates

It is possible to create your own templates and add them to the above list. Your instructor may supply you with predefined templates and ask you to install them in NetBeans.

Step 1 - Transfer the predefined template files to your PC.
Predefined template files may supplied to you on a floppy disk, CDROM, or the Internet. If they are on the Internet you must first download them to your PC. Here are two sample predefined templates to install. These templates are based upon files originally written by UMUC instructor Jerry Rugg.
Click on each of the links above and save the files to your PC.  Depending upon your PC and/or browser configuration, you may have to use a shift left mouse click to obtain a dialog box that will enable you to save the files to your PC. The diagram below shows the location where I downloaded the files to my PC.

Dowloaded Template Files

Step 2 - Start NetBeans and mount the filesystem directory where you downloaded the template files.
If you forgot how to mount existing files, refer to Hot-To Use Existing Files with NetBeans. The template files can be mounted in any project. After they have been installed, the original files can be deleted. The default project is a good project for this task.

Mount Template Files

Step 3 - Install the template in NetBeans
Right click on the file name in the left hand Filesystems window. In the drop down list that appears, click on Save as Template ... .

Click Save as Template

In the dialog box that pops up, click on Java Classes then click the OK button.

Install Template

That's it. The template has been installed. The name of the template will be the name of the file. The next time that you create a new Java Class source file, this will be in the list of templates from which you can choose.

Installed Template

Step 4 - Delete the original template files and unmount the filesystem.
The original template files are no longer needed. They can be deleted and the filesystem unmounted.
Delete a file by right clicking on its name and then chose Delete from the dialog box that pops up. You will be asked to verify the deletion. Unmount a filesystem by right clicking on its name and then choose Unmount Filesystem from the dialog box that pops up.

Delete original file

Return to How-To Home

Last modified: 01 July 2004