Tips and Tricks for Using NetBeans IDE v3.6

Prof. Jesse M. Heines

UMass Lowell Computer Science


The NetBeans home page on the Web is located at:  http://www.netbeans.org

To switch to the multiple document interface, which is just like JPadPro and Visual C++ and the like and much more convenient to use (IMHO):

  1. Go to Tools->Setup Wizard...
  2. Click the Full Screen Mode ("MDI") radio button in the middle of the first screen
  3. Click the Finish button

To reset the tab size (the default is 8 which is far too large; I suggest 2):

  1. Go to Tools->Options...
  2. Expand Editing->Editor Settings->Java Editor
  3. Click in Tab Size value field and change 8 to 2
  4. I also recommend setting the Line Numbers value to True in this same window
  5. Note that if you want to set this tab size in all editors (HTML and JSP have their own settings), you must do this in each entry under Editing->Editor Settings

To make all editors insert spaces instead of tabs (this is a global setting):

  1. Go to Tools->Options...
  2. Expand Editing->Indentation Engines->Java Indentation Engine
  3. Click the Expand Tabs to Spaces value field and select True
  4. Click the Number of Spaces per Tab value field and change its value to 2 (or whatever value you desire)

To set parameters for generated Javadoc

  1. Go to Tools->Options...
  2. Expand Code Documentation->Doclets and click Standard Doclet
  3. Check the Author and Version checkboxes
  4. To force the system to ask you where to put the generated Javadoc
    1. Click the Documentation subnode of the Code Documentation tree
    2. Check the Ask for Destination Directory checkbox

To generate the Javadoc for a program

  1. Load the program into the editor if it is not there already
  2. Go to Tools->Generate Javadoc
  3. If you set the Ask for Destination Directory option (see above), click the Browse... button in the Javadoc Destination Directory dialog box if you wish to store the Javadoc output in a directory other than the one displayed

Note that NetBeans does not allow you to set three very important options for the Javadoc tool: -version, -breakiterator, and -classpath.  I therefore recommend that you do not generate your Javadoc from inside NetBeans.  Instead, use the command:

javadoc -private -author -version -breakiterator -d doc [-classpath path to add] list of Java files to process

If you don’t need the -classpath option, the following DOS batch file makes the process a bit more convenient:

@echo off

: File jd.bat -- passes Java files to javadoc
: Jesse M. Heines, UMass Lowell Computer Science, heines@cs.uml.edu
: Copyright (c) 2004 by Jesse M. Heines.  All rights reserved.  May be freely 
:   copied or excerpted for educational purposes with credit to the author.
: updated by JMH on September 04, 2004 at 04:44 PM

if not [%1]==[] goto ParameterSupplied
echo ERROR: A Java program name must be supplied, with the .java extension.
goto exit

:ParameterSupplied
: make a doc directory if necessary
if not exist doc mkdir doc

: check for existence of specified files
set filename=%1
if not [%filename%]==[] if not exist %filename% goto error
set filename=%2
if not [%filename%]==[] if not exist %filename% goto error
set filename=%3
if not [%filename%]==[] if not exist %filename% goto error
set filename=%4
if not [%filename%]==[] if not exist %filename% goto error
set filename=%5
if not [%filename%]==[] if not exist %filename% goto error
set filename=%6
if not [%filename%]==[] if not exist %filename% goto error
set filename=%7
if not [%filename%]==[] if not exist %filename% goto error
set filename=%8
if not [%filename%]==[] if not exist %filename% goto error
set filename=%9
if not [%filename%]==[] if not exist %filename% goto error

: all files exist, call javadoc
@echo on
javadoc -private -author -version -breakiterator -d doc %1 %2 %3 %4 %5 %6 %7 %8 %9
@echo off
goto exit

:error
echo ERROR: File %filename% does not exist.

:exit

To modify the default Templates that format new programs

Note:  Further information is available at http://developers.sun.com/prodtech/javatools/jsstandard/reference/tips/tip02-11-01.html

  1. Go to Tools->Options...
  2. Expand Source Creation and Management
  3. Expand Templates
  4. Expand Java Classes
  5. Expand the type of class for which you wish to modify the template, typically Java Class or Java Main Class
  6. Right-click on the class for which you wish to modify the template and select Open from the popup menu
  7. Edit the code in the window that appears in your IDE

Note:  Modified templates are stored in directory C:\Documents and Settings\username\.netbeans\3.6\system\Templates\Classes.  These template files are only read when NetBeans is first started.  Therefore, if you copy these files from one system to another while NetBeans is open, you must shutdown NetBeans and restart it for the changes to take effect.

To change the values (macro text strings) used in Templates

Note:  These are the strings that can be inserted by preceding and following their names with double underscores such as __USER__)

  1. Go to Tools->Options...
  2. Expand Editing->Java Sources
  3. Click the ... button to the right of the Strings Table property
  4. Edit the appropriate string
  5. Example:  I changed my USER string to:
    USER=Jesse M. Heines, UMass Lowell Computer Science,\n
    <a href="mailto:heines@cs.uml.edu">heines@cs.uml.edu</a>

For additional information on NetBeans macros and the built-in macro text strings

  1. Go to Help->Help Contents
  2. Navigate to:

The IDE has the following uneditable macros

Macro Generated String
__DATE__ Substitutes the date of template creation.
__TIME__ Substitutes the time of template creation.
__NAME__ Substitutes the name of the class (without extension).
__PACKAGE__ Substitutes the name of the package that the class is in. Do not use this macro for the package statement in a Java class. It is better to provide the package statement for the template itself. When a class is created from a template, the package statement is automatically changed to reflect the package that the class is created in.
__PACKAGE_SLASHES__ Substitutes the name of the class's package. However, the name is delimited with slashes (/) instead of periods (.).
__PACKAGE_AND_NAME__ Substitutes the name of the package and the file, substituted in the form packageName.fileName. If the file resides in the root of the filesystem, it is substituted only with the filename.
__PACKAGE_AND_NAME_SLASHES__ Works the same as PACKAGE_AND_NAME. However names are delimited with slashes (/) instead of periods (.).
__QUOTES__ Substitutes a double quote mark ("). This macro is necessary if you want to place a macro between quote marks. If you enclose a macro in actual quotes in the template, text substitution for that macro does not occur when you create an object from that template.

To make Shift-F1 and Alt-F1 and right-clicking a Java keyword bring up the corresponding Javadoc page:

Note:  Shift-F1 brings up the page in the IDE, Alt-F1 launches your default browser and displays the page there

  1. Go to Tools->Javadoc Manager
  2. Mount the <j2sdk1.4.0 installation directory>\docs\api directory

To do a “Save As...”

Note:  Unfortunately, there is no “Save As...” function in NetBeans.  8-(  To accomplish this task, you need to go through a few steps.

  1. Make sure that all the files in your editor windows have been saved (File->Save)
  2. Right-click the name of the file you want to copy in the Filesystems Explorer window
  3. Select Copy from the pop-up window
  4. Right-click the parent node of the explorer tree branch in which you want to save the copy
  5. Select Paste->Copy from the pop-up window and NetBeans adds a node to the tree with the name of your original file plus “_1”
  6. Right-click the new tree node and select Rename... from the pop-up window
  7. Enter the name you desire for the copied file and click the OK button

To generate an HTML-formatted version of your code for displaying on a Web site

  1. Make sure that the file you want to print is the active one in you editor window
  2. Go to File->Print to HTML...

blue_top.gif (282 bytes) To Top of Document           blue_prev.gif (259 bytes) Back to Previous Document