< Zurück | Inhalt | Weiter >

10.2.3 Getting Around in NetBeans

Let’s take a look, from top down, at NetBeans’ main window. First, of course, is the menu bar. There are lots of choices to explore there. Much of what you’ll do with NetBeans won’t require much use of the menus—there are so many shortcuts elsewhere.

Next comes a row of icons, which are just shortcuts for menu times. This row of icons can be customized, and you can even add your own (see Section 10.2.5).

The three tabs below the icons, labeled Editing, GUI Editing, and

Debugging, modify the window to provide three distinct workspaces. Each one customizes the window environment for a specific task, but it is still working on the same files.

Next, on the left, comes the Explorer, which is in many ways similar to

the tools that you may use for traversing filesystems on a Windows or Linux system.

One oddity of NetBeans is that it doesn’t just use the files as it finds them in the directories on your hard drive(s). Rather, is requires you to designate a piece of the filesystem as the part that you want to use. You can designate sev- eral such pieces. Each piece is “mounted” as if it were a mountable filesystem. (This is an operating system concept. If you’re not familiar with it, don’t worry. For the purposes of NetBeans, just think of the IDE as too dumb to know about any files until you tell it about them.)

There are three different types of files that you can mount—local, CVS, or JAR. By specifying the type, NetBeans can treat each one in its special way.

• Local files need no special treatment; they are just the local files on your hard drive.

• If a filesystem is mounted under a version control system (CVS or generic VCS), then its files can have version control operations performed on them (checkin, checkout, and so on), via commands in the IDE. (More on that below.) Also, special directories used by the version control system (e.g., CVS) are hidden from the display, as you almost never want to manipulate these files directly.

• When you mount a JAR file or ZIP archive as a filesystem, NetBeans displays the contents of the archive as if they were just files in a directory—which can make them easier to manipulate. More importantly, the JAR is automatically added to the classpath for Java compiling.

Therefore, any third-party JARs that you may need for your project should be mounted.

To mount a local directory as a filesystem, right-click on the little icon la- beled Filesystems in the Explorer [Filesystems] window. Choose Mount, then Local Directory, and you’ll get a filechooser to let you navigate your file structure and choose a directory to mount.


To ensure that NetBeans knows how to compile your source, you need to mount the directory that contains the base level of your source as a mountpoint, not just have that directory somewhere in a tree of directories.

For example, let’s say that your source is kept in two packages, com.coolco.projecta and com.coolco.util which implies that you have a directory structure with those names. Let’s further assume that you keep them in a directory called src which is itself contained in a directory called brolly, as shown in Figure 10.3.

The likely thing to do is to mount the brolly directory, since it will contain

the source and all sorts of other project-related directories. That’s fine, as far as it goes. But since the mountpoints in NetBeans are also the CLASSPATH directories, you need to also mount brolly/src, so that directories like com/coolco/util are found when your Java sources have statements such as import com.coolco.util.*;.

It’s OK to have the same directory show up in different mountpoints. Net-

Beans won’t get confused, although you may. You’ll probably want to edit and compile from the mountpoint of, in this example, brolly/src. The src folder inside the brolly mountpoint would refer to the same files. Just keep the one always open and the other closed, and you should be able to keep them straight.

image Filesystem versus Project

The Explorer window has tabs at the bottom which let you look at different aspects of your work. In some instances you’ll want the Project view. For this, you have to mount file’s from the already mounted filesystems in the Filesys- tem view. Seems redundant, no? The Project view lets you set properties for the project as a whole or for individual files in the project. These settings apply to that file only for the project. Another project, looking at the same files, might have different settings.

For now, don’t worry about the difference. Many people like to work in the Filesystem view and never bother with projects. Others, especially those working on multiple products or projects, like Projects as a way to switch

















Figure 10.3 A simple source structure

between tasks—you can only have one project active at a time, but when you switch projects, it switches all the mounted filesystems and other settings that you have configured. Editing

Like other IDEs, NetBeans provides its own editing window. It’s a GUI point- and-click environment, with syntax highlighting and other helpful features for a programmer.

At the top of the editing window is a toolbar (Figure 10.4). Each icon on the toolbar has a tooltip, a help text that pops up when you rest your mouse pointer over the icon, to explain the somewhat cryptic little icons. Most of the tools are quite handy. With the pulldown menu, you can navigate to any method or class variable within the class. The next four buttons deal with searching: Select any text in your source file, click on the magnifying glass icon, and the search will be performed for the next occurrence of that text. In addi- tion, all occurrences are highlighted. This highlighting can be toggled on or off.


Figure 10.4 NetBeans’ Edit screen toolbar


Figure 10.5 NetBeans’ Find dialog

The toolbar search only works within a single source file. If you want to search across multiple files, go back to the Explorer window and right-click on the folder containing the files you wish to search. There is a Find . . . com- mand in the pop-up menu. That brings up a dialog box (Figure 10.5) that has multiple tabs for quite extensive filtering of your search. In its simplest use, just type in the text you want to find, and press Enter.

A list of the files which contain the text will appear in a different window, citing filename and linenumber for each file. There you can double-click on any citation to bring up that file in the edit window, at that location.

If you heeded our admonition to learn vi, you’ll be glad to know that

NetBeans can handle the fact that the source files can be modified externally from the IDE. Go ahead and edit any of your source files, even while the IDE

is running. When you next touch the file from within the IDE, NetBeans will recognize the fact that the file has been modified and load the new version.

If you haven’t yet learned vi, you may find yourself quite comfortable us-

ing the NetBeans editor. If you dig deeper into NetBeans you can find how to map certain keystrokes to make it even more editor-like. However, mousing and cut-and-paste may suffice for beginners for quite some time.