NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
Authors: Keegan P. Chempenois L. Crawley G.
Published year: 2004
Pages: 68-70/279
Buy this book on amazon.com >>


Opening the Source Editor

Before starting to work in the Source Editor, you will typically want to have an IDE project set up. You can then open an existing file or create a new file from a template. See Chapter 3 for basic information on creating projects and files and for a description of the various file templates.

If you would simply like to create a file without setting up a project, you can use the Favorites window. The Favorites window enables you to make arbitrary folders and files on your system accessible through the IDE. The Favorites window is not designed for full-scale project development, but it can be useful if you just want to open and edit a few files quickly.

To use the Source Editor without creating a project:

  1. Choose Window Favorites to open the Favorites window.

  2. Add the folder where you want the file to live (or where it already lives) by right-clicking in the Favorites window, choosing Add to Favorites, and choosing the folder from the file chooser.

  3. In the Favorites window, navigate to the file that you want to edit and doubleclick it to open it in the Source Editor.

    If you want to create a new file, right-click a folder node, choose New Empty File, and enter a filename (including extension).



Managing Automatic Insertion of Closing Characters

When typing in the Source Editor, one of the first things that you will notice is that the closing characters are automatically inserted when you type the opening character. For example, if you type a quote mark, the closing quote mark is inserted at the end of the line. Likewise, parentheses(()), brackets ([]), and curly braces () are completed for you.

While this might seem annoying at first, the feature was designed to not get in your way. If you type the closing character yourself, the automatically inserted character is overwritten. Also, you can end a line by typing a semicolon (;) to finish a statement. The semicolon is inserted at the end of the line after the automatically generated character or characters.

See the following subtopics for information on how to use the insertion of matching closing characters.

Finishing a Statement

When the Source Editor inserts matching characters at the end of the line, this would appear to force you to move the insertion point manually past the closing character before you can type the semicolon. In fact, you can just type the semicolon without moving the insertion point, and it will be placed at the end of the line automatically.

For example, to get the line

ArrayList ls = new ArrayList();


you would only have to type

ArrayList ls = new ArrayList(;


Splitting a String Between Two Lines

If you have a long string that you want to split between two lines, the Source Editor adds the syntax for concatenating the string when you press Enter.

For example, to get the lines

String s = "Though typing can seem tedious, reading long" +
"and convoluted sentences can be even worse."


you could type

String s = "Though typing can seem tedious, reading long
and convoluted sentences can be even worse.


The final three quote marks and the plus sign (+) are added for you.

If you want to break the line without creating the concatenation, press Shift-Enter.



Displaying Line Numbers

By default, line numbers are switched off in the Source Editor to save space and reduce visual clutter. If you need the line numbers, you can turn them on by choosing View Show Line Numbers. You can also right-click in the left margin of the Source Editor and choose Show Line Numbers.


NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
Authors: Keegan P. Chempenois L. Crawley G.
Published year: 2004
Pages: 68-70/279
Buy this book on amazon.com >>