Working in the editor

JBuilder has a superb code editor with many features for making the task of writing code quicker and easier.

To open a file in the editor, either double-click a text-based file in the project pane (upper left pane) or select the file and press Enter. Note the file status bar at the bottom of the editor, indicating the file name, the cursor location (line number and column), and the insertion mode of a text-based file.

The editor offers a variety of productivity features, such as brace matching, keyboard shortcuts, syntax highlighting, customizable editor keymappings, coding shortcuts (including Javadoc coding shortcuts), searching, and printing, as well as a fully customizable editor. Many of these features can be set in the Editor Options dialog box (Tools|Editor Options).

Many more features are available from the editor's context menu. These features vary based on which JBuilder edition you use, what your project settings are, and where the cursor is in the editor when you invoke the menu. Right-click with your cursor in the editor or click the editor and press Shift+F10 to display the context menu.


Selecting a keymapping for the editor

Keyboard shortcuts make certain tasks much faster and easier to do. Different editors map different keystrokes to the same action. This makes switching between editors inconvenient at best, risky at worst.

Because different programmers have different habits and preferences, JBuilder provides a number of editor emulations. Choose the one that you're most comfortable with:

When you first install JBuilder for Windows, Linux, or Solaris, the CUA keymapping will be in effect.

To select a different keymapping scheme for the editor,

  1. Click the drop-down arrow just to the left of the magnifying glass at the right side of the status bar.

  2. Choose the keymapping scheme of your choice.

You can also use either the IDE Options or Editor Options dialog box to change the keymapping scheme.

  1. Choose Tools|IDE Options and select the Browser page, or choose Tools|Editor Options and select the Editor page.

  2. Click the Keymap field and select the editor emulation you want from the drop-down menu.

  3. Choose OK.

The new keymap emulation is active immediately.

 

Customizing keymaps

You can customize the selected keymapping using the Keymap Editor.

To access the Keymap Editor,

  1. Choose Tools|IDE Options and select the Browser page or choose Tools|Editor Options and select the Editor page.

  2. Click the Customize button next to the Keymap field.

  3. Click the command you want to change, remove, or add a keymapping to.

  4. Click the button that allows you to perform the action you want: Change, Remove, or Add.

  5. Click the table headers to change the sort order.

CUA Keymap Editor

CUA Keymap Editor dialog box

For more information about using the Keymap Editor, click its Help button.



Splitting the source view

The editor lets you split the source view of a file into two or more vertical or horizontal panes. This setting applies to an individual file, not to all the opened files in the content pane. You can have a different configuration for every opened file.

To split the view, right-click the Source pane and choose either Split Vertically or Split Horizontally. To return a split view to one pane, right-click in each pane and choose Close View.


Line numbers

The editor has an option to display line numbers in the left gutter margin.

Editor view with line numbers

This feature can be turned on and off with the Line Numbering option on the Editor page of the Editor Options dialog box (Tools|Editor Options). It is also possible to instantly move the cursor to a specific line number by choosing Search|Go To Line, and entering the line number. Both of these features are accessible from shortcuts on the status bar.

Displaying line numbers

You can quickly control line numbering from the status area at the bottom of the editor. The line number and column number for the location of the cursor is always displayed on the status bar. To the right of this display is a drop-down arrow.

Line number display

To show line numbers, click the drop-down arrow and select Show Line Numbers. To hide them, click the drop-down arrow and uncheck Show Line Numbers.

Line number menu on status bar

Going to a specific line

To go to a specific line number, click on the line/column number display itself, or click the down-arrow beside it and choose Go To Line to bring up the Go To Line Number dialog box and enter the number of the line.

Go To Line

Alternatively you can press Ctrl+G to bring up the Go To Line dialog box.


Selecting text

There are a variety of ways to select text in the editor. Use the mouse to select a section of text, or place the cursor at the starting location, then while holding down the Shift key, click the left mouse button at the end of the selection area. You can also use Ctrl+Shift with the arrow keys to highlight words and lines quickly.

In addition to these, there are shortcuts in the editor for quickly selecting entire lines of text using the line number display in the gutter margin.

Note: To use these shortcuts, make sure line numbers are displayed in the gutter margin (see Displaying the line numbers above.)

Selecting an entire line

Click on a line number to select that entire line.

Selecting a block of line numbers

You can select a contiguous block of lines without having to scroll. Click the first line number in the gutter margin, hold the Shift key down and click the last line number.

Selecting all line numbers

To quickly select all the lines in the entire file, place the cursor in the gutter over any line number and press Ctrl and click on the line number with the mouse.


Dragging and dropping text

You can drag and drop selected text in the editor. Highlight the desired text then drag it with the mouse to the new location. If you are moving an entire line of text, and the Smart Paste option is selected in the Editor Options, the line will be automatically indented for you when you drop it on the new line.

Resizing the font used in the editor

You can quickly resize your code font in the editor.

To enlarge the font size of your code, click the magnifying glass icon at the right side of the status bar of the editor. Each time you click the icon, your text grows larger. You can also increase the font size by clicking the pull-down arrow next to the magnifying glass icon and choosing Zoom In.

To decrease the size of your code, click the pull-down arrow next to the magnifying glass icon and choose Zoom Out.

To return the size of the text in the editor to its default size, click the pull-down arrow next to the magnifying glass icon and choose Normal.

You can also change both the font and its size using the Tools|Editor Options dialog. Click the Display tab and make your changes and use the Editor Font options on that page. Click the Help button in the dialog box if you need more information.

For information about changing the size of the font used by the entire IDE including the editor, choose Tools|IDE Options and click the Help button to read about the Font Size Increase option on the Browser page of this dialog box.


Finding text in the editor

The editor provides numerous ways to find and replace specific text in a file. Search commands are located on the Search menu as well as from icons in the main toolbar. Modify search options on the Editor page of the Editor Options dialog box (Tools|Editor Options|Editor).

Commands for finding text

Task Command
Find text Search|Find
Search for text across all files in the selected path(s) Search|Find in Path
Find text and replace it with new string Search|Replace
Search for the same text again Search|Search Again
Search for text incrementally, as you type in the search string Search|Incremental Search
Go to a specific line number Search|Go To Line
Browse through a class, interface, or package Search|Find Classes
Find the declaration of a variable, method, class, or interface Search|Find Definition
Find uses or instances of a variable, method, class, or interface Search|Find References
Navigate to a specific item in the history list View|History
Navigate to the previous item in the history list View|Back
Navigate to the next item in the history list View|Forward
Set bookmarks and return to them Key combinations listed in the keymap file (Help|Keyboard Mappings)

The Find dialog box and the Replace dialog box both provide the option to replace text. Other options in these dialog boxes include case-sensitive searching, the use of wildcards or regular expressions, and defining the extent of the search/replace task. Click Help in these dialog boxes to learn about using about these options.

Finding a symbol's definition

The Find Definition command, available from both the editor's context menu and the Search menu, allows you to navigate from the usage of a symbol to its definition. Before you can find a symbol's definition, you must have compiled your project and the class that contains the definition must be on the import path.

To see how a symbol is defined, right-click the symbol you want to see defined and choose Find Definition.

  1. Position the cursor in the editor on the symbol you want to see defined.

  2. Right-click the symbol and choose Find Definition.

The source file where the symbol is defined is opened in the editor, with the cursor positioned on the symbol's definition.

Finding references to a symbol

The Find References command, available on the Search menu and on the editor and structure pane context menus, allows you to discover all source files that use a given symbol.

To find all references to a symbol, right-click the symbol and choose Find References.

To discover the source file(s) where the reference exists, expand a category node and traverse the hierarchy tree in the message pane. Double-click a reference to open the source file and to position the cursor directly on the reference in the file.

Important: To find references to your selected symbol, you must have already compiled your project. For more information, see "Setting up for references discovery and refactoring" in "Refactoring code symbols" in Building Applications with JBuilder.

Finding the overridden method

You can find the superclass of your method with the Find Overridden Method command available from the editor or structure pane context menu.

  1. Compile your project.
  2. Right click your method from the editor or structure pane.
  3. Choose Find Overridden Method.

The Find Overridden Method command takes you to the correct super class and highlights the method that you have overridden. You can navigate up the chain of superclasses to find all of the overridden superclass methods. The Find Overridden Method menu option is grayed out if the method does not override a super class method.

Formatting your code

You can specify your formatting preferences and automatically format your source code. To access these settings, choose Project|Project Properties and click the Formatting tab.

Formatting Page

The tabs on this page allow you to customize your code formatting by specifying the following types of preferences:

On each page is a Preview window that displays what the selected preference will look like.

Applying formatting to your code

To apply the formatting to your code, open a file in the editor and choose Edit|Format, or press the Tab key.

Important: Formatting properties apply to all files in a project.

You can also export your code formatting preferences, or import previously saved preferences using the Import and Export buttons at the bottom of the Formatting tab in the Project Properties dialog box.

For details on setting code formatting options, press the Help button at the bottom of the Formatting page of the Project Properties dialog box.

Javadoc shortcuts in the editor

Javadoc is a Sun Microsystems utility that generates HTML documentation files from comments you enter in API source files. The comments must be formatted according to Javadoc standards. Use JBuilder's Javadoc wizard (Wizards|Javadoc wizard) to set up properties for generating Javadoc (JBuilder Developer and Enterprise). Then, when you build your project, Javadoc is automatically generated.

To make coding Javadoc comments easy, the JBuilder editor contains a Javadoc comment template that is activated when you type /** and press Enter. The template automatically adds the Javadoc end comment symbol, */. If the cursor is positioned immediately before a class, interface, or method signature the template expands to include appropriate Javadoc tags.

To quickly add a Javadoc comment block,

The editor automatically adds the Javadoc end comment symbol and positions the cursor in the second line of the comment. If necessary, it adds appropriate tags.

For example, entering /** before the import statements in a class source file generates the following comment block:

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2001</p>
 * <p>Company: </p>
 * @author 
 * @version 1.0
 */

When you enter /** for the following method signature:

  public void addValues(Double valueOneDouble, Double valueTwoDouble)

Javadoc creates the following Javadoc comment:

  /**
   *
   * @param valueOneDouble
   * @param valueTwoDouble
   */

Using JavadocInsight in the editor

You can add custom Javadoc tags to your Javadoc and enter Javadoc tags into a Javadoc comment block using JavadocInsight. You can also color-code Javadoc differently from normal line and block comments.

To access the JavadocInsight window and see the list of Javadoc tag options,

To access the JavadocInsight page to see font and color options,

To display the Javadoc page of the Project Properties editor so you can create, remove, or edit custom Javadoc tags, choose Project|Project Properties|Build|Javadoc. Once the Javadoc page appears, use it to accomplish one of these tasks:

You can also use options on the Javadoc page to add text for the custom tag that displays in Javadoc output as a header.

For more information about JavadocInsight, see "JavadocInsight" in Building Applications with JBuilder.

Using @todo tags in the editor

Javadoc @todo tags are useful for adding reminders about what needs to be done to an area of code. Place Javadoc @todo tags inside of Javadoc comments. These @todo tags appear in JBuilder's structure pane in a To Do folder.

JBuilder's code templates make adding @todo tags to your code very easy.

  1. Type todo at the appropriate indentation level in the editor.

  2. Press Ctrl+J to expand the template in your code:
    /**  @todo <cursor placed here> */
    

Some of JBuilder's wizards generate @todo tags as reminders to add code to the stub code that the wizard generates.

Printing support in the editor

You can use the File|Print command to print your source code directly from the editor.

The File|Page Layout command displays the Page Layout dialog box, where you can set layout options:



Dragging a file into the editor

You can use drag and drop to bring an external file from outside JBuilder into the editor. The file must be a type that JBuilder recognizes. After you drag the file from an external source and drop it into the project pane, the file is opened in the editor and added to the project. You can also add a file to your project using the Add Files/Packages/Classes button at the top of the project pane or right-click the project file in the project pane and choose Add Files/Packages/Classes. The drag and drop feature is an option that can be turned off in the Editor Options dialog box.


Customizing the editor

You can customize how the editor appears and works in many ways. For example, you can change the font and font size used in the editor, enable or disable line numbering, specify your favorite colors for editor elements, determine how you want elements in the structure pane to appear, customize how common keystrokes behave, and much more. You can also specify how you want various CodeInsight features to work, and you can edit and even create your own code templates.

Use the Editor Options dialog box to customize the editor. To access the dialog box, choose Tools|Editor Options. For complete information about all the options available to you, click the Help button on the various pages of the Editor Options dialog box. You can also read about customizing the editor by choosing Help|JBuilder Environment and selecting the "Customizing the editor" topic.