BUY THIS BOOK
Add to Cart

Print Book $44.95


Safari Books Online

What is this?

Add to UK Cart

Print Book £31.95

What is this?

Looking to Reprint this content?

NetBeans: The Definitive Guide
NetBeans: The Definitive Guide

By Tim Boudreau, Jesse Glick, Simeon Greene, Vaughn Spurlin, Jack J. Woehr
Price: $44.95 USD
£31.95 GBP

Cover | Table of Contents | Colophon


Table of Contents

Chapter 1: Getting and Installing the IDE
NetBeans has a set of basic requirements that must be checked before attempting to run the IDE. This section details these requirements.
Large and complex Java programs are demanding of memory and processor resources, and NetBeans is no exception. Furthermore, whereas some programs can anticipate approximately how much memory or CPU time they will need, NetBeans, which allows the user to design an arbitrarily complex project, can make no such a priori assessment.
The absolute minima for running NetBeans are much more modest than the practical minima. For instance you can run NetBeans on an AMD 5x86 at 166 MHz with 64 MB of RAM and a 640 X 480 screen resolution, but only if you have no real work to do in NetBeans or any other tasks to perform on the machine in question. We know because we have tried it.
That said, we list in Table 1-1 the practical minima for running NetBeans on several popular platforms. These are of necessity somewhat subjective. One rule of thumb is that serious developers should take our word on the minima, but you can get by with less machine than we recommend if you only plan to explore NetBeans lightly (preparatory to finding yourself a more satisfactory platform on which to do serious development).
Table 1-1: NetBeans minimum requirements on several popular platforms
Platform
Processor (MHz)
Memory (MB)
Disk (MB)
Screen resolution
Color palette
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Platforms and Requirements
NetBeans has a set of basic requirements that must be checked before attempting to run the IDE. This section details these requirements.
Large and complex Java programs are demanding of memory and processor resources, and NetBeans is no exception. Furthermore, whereas some programs can anticipate approximately how much memory or CPU time they will need, NetBeans, which allows the user to design an arbitrarily complex project, can make no such a priori assessment.
The absolute minima for running NetBeans are much more modest than the practical minima. For instance you can run NetBeans on an AMD 5x86 at 166 MHz with 64 MB of RAM and a 640 X 480 screen resolution, but only if you have no real work to do in NetBeans or any other tasks to perform on the machine in question. We know because we have tried it.
That said, we list in Table 1-1 the practical minima for running NetBeans on several popular platforms. These are of necessity somewhat subjective. One rule of thumb is that serious developers should take our word on the minima, but you can get by with less machine than we recommend if you only plan to explore NetBeans lightly (preparatory to finding yourself a more satisfactory platform on which to do serious development).
Table 1-1: NetBeans minimum requirements on several popular platforms
Platform
Processor (MHz)
Memory (MB)
Disk (MB)
Screen resolution
Color palette
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Getting and Installing a JDK
You need the JDK installed on your computer to run NetBeans.
Sun Microsystems' JDK consists of:
  • The runtime engine for the Java programming environment
  • The compiler and other basic tools essential to Java development
  • The fundamental Java class libraries that make Java usable
The Java Runtime Environment (JRE) consists of:
  • The runtime engine for the Java programming environment
  • The fundamental Java class libraries that make Java usable
The JRE is a runtime for users. The JDK is the complete software development environment for Java. Sun and other Java implementors provide the JRE packaged independently of the JDK. Everything that is in the JRE is also in the JDK—the JDK is a pure superset of the JRE.
You will need the full JDK to do NetBeans development. NetBeans uses the development tools in the JDK to do much of its work.
Many operating systems nowadays, such as Linux and Solaris, come with a JDK pre-installed. Even so, you may want to obtain a later version of the JDK. At the web site java.sun.com (http://java.sun.com/) you can obtain free of charge the JDK for the following operating environments:
  • Linux
  • Solaris (both for Sparc and x86 architectures)
  • Microsoft Windows
Other JDKs exist for various platforms created by various other vendors and open source software organizations. Among them are:
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Which IDE Distribution?
You have several choices when picking a distribution of the NetBeans IDE to download and run on your personal computer or workstation. Your choices are
  • Download or order the current Sun ONE Studio 4 packaging of NetBeans from the Sun ONE Studio 4 web site (http://wwws.sun.com/software/sundev/jde/index.html).
Sun ONE Studio 4 is the product formerly known as Sun Forte for Java.
  • Download the latest stable release of NetBeans from the NetBeans downloads page (http://www.netbeans.org/downloads.html).
  • Download an earlier stable release of NetBeans from the NetBeans downloads page (http://www.netbeans.org/downloads.html).
  • Download a reasonably stable beta release of NetBeans from the NetBeans downloads page (http://www.netbeans.org/downloads.html).
  • Download the latest build of NetBeans from the NetBeans downloads page (http://www.netbeans.org/downloads.html).
  • Download the Q-build of NetBeans from the NetBeans Q-Builds Program (http://qa.netbeans.org/processes/q-builds-program.html).
Your choice will balance the trade-off between stability, commonality of experience with a wide range of developers of all skill levels, and advanced technology, as summarized in Table 1-2.
Table 1-2: Summary of trade-offs between NetBeans releases
Release
Advantages
Disadvantages
Sun ONE Studio 4
Sun ONE Studio 4 cuts of the NetBeans IDE are the most stable and long-lived cuts. Patches are offered via the Update Center (see Section 1.7.1). Sun attempts to see that their enterprise customers and less adventurous developers have a reliable environment for routine Java development, one that possesses a clearly defined relationship to the trusted name and service offerings of Sun Microsystems.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Installing Binary Distributions
It's easy to install a binary distribution of NetBeans, whether it's the current stable release, a beta, or a Q-build.
  • On Windows, the distribution archive is itself an executable file. Run the installation .exe which will:
    • Unpack all files from within itself
    • Install all required program objects and ancillary files
    • Create a shortcut to NetBeans on your desktop from which you may start the application
  • On Unix, unpack the distribution archive and move the unpacked tree to an appropriate file system location.
  • On all platforms, be sure to read any and all Readme files found with the distribution. These files give up-to-the-minute information on installation issues and runtime issues. This especially applies to less widely used platforms such as Macintosh and OpenVMS.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Building the IDE from Source (Simple Builds)
In this section we are going to build NetBeans from source. You can skip this section if you don't want to build NetBeans from its source code. However, it's easy to build NetBeans, so you might as well try it once just for fun.
We're going to do a simple, straightforward build, no special options, no personal changes to the source code. If you are intererested in modifying NetBeans and rebuilding it, adding modules of your own to NetBeans, and advanced options, you will want to read Chapter 13.
To get started with developing and building NetBeans, first visit NetBeans DevHome (http://www.netbeans.org/devhome/), which has explanations of how to download NetBeans source code and the latest information on builds.
To build the IDE you need several items:
  • A correctly configured installation of the Java Development Kit
  • The NetBeans source
  • Certain binary-only objects (sometimes called the extra binaries) distributed without source required for a NetBeans build
  • The Jakarta Ant build system from the Apache Project
The NetBeans extra binaries include a version of Ant sufficient to build the IDE. It is not necessary to download Ant separately.
For special issues pertaining to building NetBeans under Mac OS X, please see the web page Using NetBeans on Mac OS X (http://www.netbeans.org/ide/support/mac.html).
Assuming that you now have the NetBeans sources archive file (or have performed an anonymous CVS checkout from the NetBeans source server) and that you also have downloaded the extra binaries archive (each typically a .tar.gz GNU zipped tar file or a .zip Windows-style zip file) downloaded to your machine, proceed through the following steps to build NetBeans:
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Running the IDE
By now you're about ready to run the NetBeans IDE. Let's take one last look at what's necessary to launch NetBeans.
Once the minimal hardware and software requirements are met, all you need to get ready to run NetBeans is to make sure the minimal environmental requirements are met. There's really only one: NetBeans must be able to find the Java Development Kit.
  • On Unix installations, the variable
    JDK_HOME
    must be set to the root of your JDK installation, something like
    JDK_HOME=/usr/java; export JDK_HOME
  • On Mac OS X, the JDK is found in /Library/Java/Home. Open the command shell (Finder Applications Utilities Terminal) from which you will launch NetBeans. The shell given you in the OS X Terminal application is, by default, tcsh. In tcsh issue the command:
    setenv JDK_HOME
            /Library/Java/Home
    If you are using a shell such as bash or zsh, the syntax will be as for Unix above,
    JDK_HOME=/Library/Java/Home; export JDK_HOME
    For special issues pertaining to launching NetBeans under Mac OS X, please see the web page Using NetBeans on Mac OS X (http://www.netbeans.org/ide/support/mac.html).
  • On Windows, NetBeans expects to be able to find the Java executable in your
    PATH
    variable. Either set this variable in the current command line session, for example,
    SET PATH=C:\JDK1.3;%PATH%
    or use MyComputer Properties
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Updating the IDE Automatically
NetBeans can automatically upgrade its core and extension modules over the Internet.
NetBeans has a module that can run periodically on your behalf and check for updates to the revision of NetBeans which you are using. The Update Center also can download and install such upgrades on your behalf if you wish.
Use the Update Center Wizard to configure various factors for the Update Center, such as
  • Update site
  • Frequency of update checks
  • Proxy usage
You can see these options in Figure 1-4.
Figure 1-4: Configuring the Update Center using Update Center Wizard
You also use the Update Center to install optional modules and even experimental modules currently under development. Once the Update Center has loaded, explore the modules offered and try anything you like, such as the new XML Tree Editor.
Both changing between the MDI/SDI interface and controlling the Update Center can also be performed through the Setup Wizard (shown in Figure 1-5), along with installing and configuring NetBeans modules. Pull down Tools Setup Wizard to launch the Setup Wizard, or just use it when it pops up automatically the first time you start NetBeans.
Figure 1-5: Configuring SDI/MDI using Setup Wizard
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
You're Now Running NetBeans
If you got this far in the book, you're now running NetBeans. You might wish at this point to simply run through the tutorial that is part of the NetBeans online help. Pull down Help Help Sets Core IDE Help. Pull down Help Contents for the whole story.
And if you find yourself faced with problems not covered in this book, try NetBeans Frequently Asked Questions (http://www.netbeans.org/ide/support/faqs) on the web.
We hope you enjoy NetBeans.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 2: Concepts and Paradigms
If you have programmed Java at the command line, or if you have used another Java IDE, you might find that many things are different in NetBeans from what you have previously experienced. The difference arises primarily because Java itself is a self-contained, abstract model of computing with its own virtual machine and memory model juxtaposed on the intent of the NetBeans designers to fulfill this model.
Java was at first intended to be an entire operating system; Sun and IBM even went a long way toward building a Java computer with a Java OS before Java retrenched and remained primarily a software virtual machine running under a host operating system. Java does not even presume the existence of a hosting hierarchical file system. Instead, it has its own hierarchy of nested packages that are Java's "native file system," as it were.
NetBeans goes a long way toward cooperating with Java's abstract model of computing. If Java really were the operating system of your computer, the GUI explorer you would use to navigate your system would look a lot like the NetBeans Explorer.
This is the essence of what is special about programming Java under NetBeans, as compared to programming Java at the command line. NetBeans leans toward presenting the Java computing universe to you from Java's point of view, not from the point of view of any particular hosting operating system.
Part of that Java view of computing is the familiar tight coupling of source objects with code objects emphasized by the package model of Java coding, including familiar details such as
  • The rule of one public class per source file
  • The hierarchical layout of packages and their applicable access rules
  • Cross-object dependency checking carried out by the compiler
NetBeans closely adapts its visual presentation of Java coding to these conceptual models. You will be in a better position to appreciate this point after you have read in this chapter and the chapters to follow about the NetBeans Explorer, Source Editor, and Object Browser.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
NetBeans and the Java Abstract Model of Computing
If you have programmed Java at the command line, or if you have used another Java IDE, you might find that many things are different in NetBeans from what you have previously experienced. The difference arises primarily because Java itself is a self-contained, abstract model of computing with its own virtual machine and memory model juxtaposed on the intent of the NetBeans designers to fulfill this model.
Java was at first intended to be an entire operating system; Sun and IBM even went a long way toward building a Java computer with a Java OS before Java retrenched and remained primarily a software virtual machine running under a host operating system. Java does not even presume the existence of a hosting hierarchical file system. Instead, it has its own hierarchy of nested packages that are Java's "native file system," as it were.
NetBeans goes a long way toward cooperating with Java's abstract model of computing. If Java really were the operating system of your computer, the GUI explorer you would use to navigate your system would look a lot like the NetBeans Explorer.
This is the essence of what is special about programming Java under NetBeans, as compared to programming Java at the command line. NetBeans leans toward presenting the Java computing universe to you from Java's point of view, not from the point of view of any particular hosting operating system.
Part of that Java view of computing is the familiar tight coupling of source objects with code objects emphasized by the package model of Java coding, including familiar details such as
  • The rule of one public class per source file
  • The hierarchical layout of packages and their applicable access rules
  • Cross-object dependency checking carried out by the compiler
NetBeans closely adapts its visual presentation of Java coding to these conceptual models. You will be in a better position to appreciate this point after you have read in this chapter and the chapters to follow about the NetBeans Explorer, Source Editor, and Object Browser.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Explorer
The user's primary tool in developing with NetBeans is the NetBeans Explorer.
The NetBeans Explorer is the NetBeans component that will become most familiar to you first. Explorer is your main interface to normal NetBeans operations on your files, objects, and projects.
NetBeans Explorer presents your project in the "explorer view," which has become a common visual metaphor in most graphical user interfaces (GUIs). All sorts of objects appear in that view, each represented as a node of the tree and having its own icon to indicate what sort of object the node represents. Representing objects as nodes allows NetBeans to construct various trees of nodes from different selection criteria. These trees offer you different collection views of the objects that make up your program and development environment.
One such view is of the objects and packages of your Java program. In this view objects and packages correspond roughly to files and folders in a typical Explorer view of a filesystem. However, each of the nodes in this type of NetBeans Explorer view represent not the individual files but rather all the files making up your class and its source lumped together. They are represented by one node; if you click on the node, it opens up into a subtree that contains more detail about the entity it represents.
NetBeans Explorer uses nodes to offer a view of your project as objects. Because the word "object" means different things in different contexts, let's make sure we know what we mean by "objects" in the context of NetBeans projects.
NetBeans Explorer nodes are representations of elements of your project as objects. An Explorer node represents, for instance, an entire class of your program as an object. This object has data members: fields and methods that belong to the class. The object has methods: actions that can be applied to the source or the byte code of the class. The object has properties: miscellaneous, generally simple aspects that can conveniently be manipulated at development time by the programmer under the familiar rubric of "properties."
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Creating Packages and Classes
To use an IDE to program Java, you have to be able to create packages of source code that you will subsequently compile.
There are two ways to create packages in your NetBeans project:
  1. You can step outside of NetBeans and create a package in your extant project. In this context, a package is just a filesystem directory. NetBeans will notice that the new package is there shortly after you create it, because NetBeans keeps an eye on the file trees grafted into its Explorer view of your project. NetBeans uses no special or hidden files to track the existence of packages, merely treating any subdirectory within a mounted tree as a package folder.
  2. You can use the NetBeans Explorer to create the package. Right-click on the package under which you wish the new package to reside to bring up the context menu, choose New Java Package, and the new package will be created.
If the tree on which you are working is under version control, the new package still needs to be added to the repository. Right-click on the new package to bring up the context menu and choose: CVS Add. This will allow you to enter any needed information in dialog boxes and then add the package to the CVS repository.
You have a package to which to add Java classes. Okay, how do you add Java classes to the package? You could step outside the IDE and use a text editor to create new classes in the package, but you've already guessed there's an easier way in the IDE itself. You're right about that: NetBeans addresses creation of classes via templates.

Section 2.3.2.1: Templates

In NetBeans IDE prototype Java classes and other source entities of all types (such as Ant build files, HTML documents, etc.) are saved as templates that can then be summoned up and instanced in your source tree as new files of the sort you want. Often the template contains macros.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Services
NetBeans possesses a somewhat detached and detachable attitude toward the most basic functionality of an IDE, including compiling, executing, and debugging your program. These services can be provided by different modules. It's all under your control, including the behavior of the specific service-providing modules you choose, on a project-by-project basis. This section discusses using the provided NetBeans services for compiling, executing, and debugging your program and how they are chosen. More detail on the operation of the services themselves, especially debugging, will be provided in later chapters.
Compiler services are how NetBeans refers to the cluster of functionality supporting the generation of object code from the sources of your project. NetBeans can use various different Java compilers, and the settings are there for you to change if you want.

Section 2.4.1.1: Compiling your code

  • To compile a Java source file, open the file in the Source Editor or select it in the NetBeans Explorer and either press F9 or right-click and choose Compile. The source file will be compiled if necessary; if the object file is up to date with respect to the source, it will not be compiled.
  • To force a source file to be compiled, even if the object is up to date, right-click on the file's representation in the NetBeans Explorer and choose Build.
  • To compile a package, select the package in the NetBeans Explorer and right-click and choose Compile. All files whose objects are not up to date with respect to the source will be compiled.
  • To force all source files in a package to be compiled, even if their objects are up to date, right-click on the package in the NetBeans Explorer and choose
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Workspaces
Workspaces are how NetBeans groups the user's work so that related tasks are associated with one another and disparate tasks can be hidden offscreen away from active tasks.
The NetBeans main window, shown in Figure 2-17, has several tabs on the bottom that tab into each of the NetBeans workspaces.
Figure 2-17: Main window workspace tabs
It's possible to download a module via Autoupdate that will allow you to flip through your workspaces via a list box instead of using tabs.
Each workspace is a view of objects opened for manipulation in a different context. When one workspace is open, only the tools, forms editing instances, and runtime instances visible in that workspace are visible. The tools, forms, and editing and runtime instances associated with other workspaces become hidden.
Sometimes you tab back and forth between NetBeans workspaces. Sometimes NetBeans itself hops to a given workspace in response to your command for a specific tool action. For instance, if you start the NetBeans debugger, NetBeans hops to the Debugging workspace.
The various workspaces have names that explain the context of each workspace. The names of each of the workspaces follow, with a brief description of their contexts.
Editing is more or less the default workspace. NetBeans initially comes up with this workspace open and with the Explorer and a Properties browser open. If you use the NetBeans Explorer to open objects in your project for editing, and those objects were not composed as forms with the aid of those modules of NetBeans that support drag-and-drop composition of GUI forms, the Editor window pops up in this workspace.
The GUI Editing workspace is where Form editors pop up. If you use the NetBeans Explorer to open objects in your project for editing, objects that were composed as forms with the aid of those modules of NetBeans that support drag-and-drop composition of GUI forms, the Editor window and associated Form editors pop up in this workspace.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Project Management
A project under NetBeans is a composite entity made up of:
  • The project's package and class hierarchy
  • The set of services for the project used to
    • Compile
    • Debug
    • Run
    • Perform version control
  • Peripheral configuration, information, and logging relating to that project, such as:
    • Optional subtargets for build operations in the project
    • Results of previous build or version control operation
    • Elements to be added to the CLASSPATH when operating on the project
You might want to work on more than one project at once. So rather than leave all these matters to global preferences, NetBeans supports the concurrent maintenance of multiple projects, each with its own setup and its own set of persistent workspaces.
If you are using NetBeans to work on one massive project, you may never bother with project management. When you launch NetBeans the first time, the default project is opened. You may continue to mount file hierarchies in the default project for as long as you like, provided there are no inherent conflicts in classpath requirements of the various subprojects you mount.
On the other hand, if you like or require a clear separation between projects, each with its own selection of filesystem mounts and archive mounts, multiple projects are well supported in NetBeans.
Pull down Project Project Manager. You are presented with a simple dialog (see Figure 2-18) that allows you to create, open, and delete projects.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Object Browser
The NetBeans Object Browser provides an object view that is a melding of the information available about your program objects from source inspection and object introspection. However, it has disappeared from the default distribution and become an optional module as of version 3.3.1, but it is still mentioned in the online help. To install the Object Browser, use the NetBeans Update Center (see Figure 2-20).
Figure 2-20: Using Update Center to install the Object Browser
The Object Browser metaphor occupies an important place in most Java IDEs. It always was important in NetBeans and has its own workspace tab once installed. It has moved off into "optional module land" in a typical open source fashion, that is:
  1. The Object Browser was showing its age.
  2. Another Object Browser-like analysis tool, the Freestyle Browser, is emerging from another open source project, and NetBeans plans to incorporate that one eventually in place of the Object Browser.
In this book we don't spend much time documenting optional IDE modules, but because object browsing is so fundamental to doing object programming in an IDE, we'll take a quick look at the classic NetBeans Object Browser, knowing that whatever replaces it eventually in NetBeans will be conceptually similar, albeit more modern and powerful.
Simply flipping to the workspace tab for Browsing invokes the Object Browser on the currently open project. The Browser windows open quickly and packages begin to appear incrementally (as seen in Figure 2-21) as the Object Browser takes a few moments to analyze your project when it first opens. Be patient.
Figure 2-21: The Object Browser open on a project
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Summary
  • NetBeans contains everything a good IDE should, and more. One difference from other IDEs is the broad flexibility provided by optional modules coded to the NetBeans open source APIs.
  • Functionality not provided by the assortment of built-in modules that accompany NetBeans installation can often be found from an optional module or experimental module installable across the Net via the NetBeans Update Center.
  • Functionality not provided either by core modules or by optional modules can be provided by your own or third-party modules.
  • The authors of NetBeans and open source contributors to NetBeans are dedicated to the ideal of making NetBeans express the essence of Java development. So, look around, it's probably there somewhere.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 3: Working with the Source Editor
Learning to use yet another source code editor was probably not high on your to-do list this year. However, the NetBeans syntax-coloring Source Editor, which is tightly integrated with the rest of the IDE, is easy to learn and is indispensible to your NetBeans development work flow.
The reason it is easy to learn the NetBeans Source Editor is that its behavior is unsurprising to anyone who has ever used a modern GUI text editor, especially one coded in Java. Try to guess what key sequences are required to copy, cut, and paste highlighted text? If you guessed Control-C, Control-X, and Control-V, respectively, you were right. Control-S saves your changes, if any exist. Shift-Right Arrow selects text to the right, Shift-Control-Right Arrow selects text to the right a word at a time. Et cetera...no surprises here.
The reason that the NetBeans Source Editor is indispensible to your NetBeans development work flow is the level of integration provided between objects in the NetBeans Explorer and Form Editor, code entities in your program, your actions within the editor, and the appearance of your code in the editor window.
There are two prinicipal ways to open a file in the NetBeans Source Editor:
  1. From the NetBeans Main Window, pull down File Open and use the file dialog to browse to the file you want to open.
  2. From within the NetBeans Explorer, find the node representing your source, right-click on it, and choose Edit if that action is available or Open if there is no specific Edit action on the menu.
Actually, with Java sources and many other NetBeans Explorer nodes, you can just double-click on the node to open it in the NetBeans Source Editor. So why the rigamarole about Open and Edit?
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Why Learn a New Editor?
Learning to use yet another source code editor was probably not high on your to-do list this year. However, the NetBeans syntax-coloring Source Editor, which is tightly integrated with the rest of the IDE, is easy to learn and is indispensible to your NetBeans development work flow.
The reason it is easy to learn the NetBeans Source Editor is that its behavior is unsurprising to anyone who has ever used a modern GUI text editor, especially one coded in Java. Try to guess what key sequences are required to copy, cut, and paste highlighted text? If you guessed Control-C, Control-X, and Control-V, respectively, you were right. Control-S saves your changes, if any exist. Shift-Right Arrow selects text to the right, Shift-Control-Right Arrow selects text to the right a word at a time. Et cetera...no surprises here.
The reason that the NetBeans Source Editor is indispensible to your NetBeans development work flow is the level of integration provided between objects in the NetBeans Explorer and Form Editor, code entities in your program, your actions within the editor, and the appearance of your code in the editor window.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Opening the Source Editor
There are two prinicipal ways to open a file in the NetBeans Source Editor:
  1. From the NetBeans Main Window, pull down File Open and use the file dialog to browse to the file you want to open.
  2. From within the NetBeans Explorer, find the node representing your source, right-click on it, and choose Edit if that action is available or Open if there is no specific Edit action on the menu.
Actually, with Java sources and many other NetBeans Explorer nodes, you can just double-click on the node to open it in the NetBeans Source Editor. So why the rigamarole about Open and Edit?
Recall from our discussion of the NetBeans Explorer that a double-click invokes the default action of an Explorer node. If you double-click on an Explorer node representing a Java class, the default action is to open its source in the Source Editor. However, if you double-click on an Ant build.xml file, the default action is to switch to the Running workspace and invoke Ant on the build file.
Very well ... now what about Open versus Edit? There are special editing modes for things like Java properties files. If you double-click on a .properties file in the NetBeans Explorer, the default action is Open, which brings up a special editor oriented toward the user filling in key-and-value pairs in string gadgets. If you instead choose Edit from the menu, you get the good ol' NetBeans Source Editor open on the actual text of the .properties file.
All files opened in the Source Editor are opened in the same Source Editor frame. They are kept separate in tabbed notebook form. You flip between the files you have opened by clicking the tabs.
Whenever your code changes, an asterisk (*) appears by the filename when the file is being displayed in the Source Editor. Control-S then saves your changes. As a result of this save, your filenames will no longer have the asterisks (until the next change, of course).
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Context Menus
When you right-click within the NetBeans Source Editor window, a contextual menu pops up. This menu has many of the selections that you would find when you right-click on the NetBeans Explorer node representation for the same entity. These selections include CVS, Compile, Build, and so on. Additionally, there are options on the menu relevant to the task of editing, such as Cut, Copy, and Paste.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Closing the Source Editor
When you click the close widget on the Source Editor window, the window closes, terminating all editing sessions. Alternatively, you may close an individual file by right-clicking on its editing window and choosing Close. In either case, if you have any unsaved changes, you will be offered the choice of saving the changes or abandoning the close operation. This choice is repeated for each unsaved, modified file until all files are closed.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Code Completion
Automated code completion is the NetBeans Source Editor's ability to supply the name of a partially entered package, class, interface, method, or member without your having to finish typing in all the characters of the name. NetBeans Source Editor keeps a database of Java classes and members and can present you with a list of candidate completions from which you select the actual completion. This wonderful labor-saving feature of the NetBeans Source Editor is useful, but it can at times be annoying.
Automated code completion is useful when you are whizzing through classes and methods the NetBeans Source Editor's database knows all about. Code completion saves typing when the editor knows what to expect.
Automated code completion is annoying when, after a predetermined timeout, the NetBeans Source Editor pops up the completion list window, obscuring your typing as you hesitate or as you try to enter something that NetBeans did not anticipate. But you can do something about that, as we'll find out below.
It's easy to turn NetBeans Source Editor code completion on and off according to your convenience.

Section 3.5.1.1: Taking advantage of code completion

To use NetBeans Source Editor code completion, just start typing a package, class, member, or method name. At some point during your typing, NetBeans should attempt to complete the component name. If NetBeans doesn't automatically attempt to complete your code, type Control-Space. NetBeans Source Editor will then pop up the completion list window if it thinks it recognizes the incomplete syntax as the name of a class or member. (See Figure 3-1.)
Figure 3-1: Code completion context window in the Source Editor
Either scroll down to the desired entry and press Enter or continue typing in further letters of the desired member or method.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Editor Colorings