This chapter includes the following sections:
JDeveloper enables you to build and assemble Java applets and client applications using JavaBeans and interactive, desktop-based GUI applications using Swing and AWT components. You can also create and run Java client applications with Java Web Start within the JDeveloper IDE.
The Java Source Editor displays Java source files, and facilitates editing of Java code. The Java Source editor is a specialized form of the generic Source Editor that JDeveloper provides for editing source code across several technologies, including XML, JSP, and HTML.
Double-clicking a node in the Applications window either opens or brings the default editor to the foreground. When a file is open in the Source Editor, its corresponding elements are displayed hierarchically in the Structure window. Double-clicking a node in the Structure window shifts the focus to the definition of that element in the Source Editor.
You can customize the behavior of the Java Source Editor by specifying preferences in the Preferences Dialog. For more information, see Setting Preferences for the Java Source Editor.
With Java Code Insight, you can filter out unnecessary information such as top-level packages, imported classes, default Object methods, deprecated items, and emphasize more key detail such as local variables, locally declared members, overloaded methods.
You can use Code Insight to speed up the process of writing code. Code Insight has two varieties: completion insight and parameter insight. You can enable or disable each independently and set the delay in seconds for each to appear when the cursor is paused at an appropriate insertion point.
To invoke completion after typing the period separator or, in the default keymap, press Ctrl+Space. To invoke parameter insight, pause after typing an opening (the left) parenthesis or, in the default keymap, press Ctrl+Shift+Space. To exit either type of insight at any time, press Esc. Note that if you change your keymap ping, these keyboard accelerators may change. You can click QuickDoc, located at the bottom right of the completion insight list, to display the Javadoc for the currently selected element
After a method has been completed by completion insight, the source editor automatically fills in the parameters based on the method code.
You can tab between these parameters, and edit them manually or using parameter insight. The source editor will automatically add an import if it can find only one exact match for an unresolved reference to a class. You can set preferences for this feature in the Preferences Dialog.
You can also use and configure member insight, the Java-specific implementation of Code Insight's completion insight, and you can choose to display deprecated members or not in Code Insight's parameter insight window.
Member insight provides you with a list of which instance and static members (fields, methods, inner classes) are accessible from a given statement context. For example, it tells you which methods you can call from any given method.
To change Code Insight settings or to view or change accelerators, from the main menu choose Tools > Preferences to open the Preferences dialog and then navigate to the appropriate page. For more information, see Editing with the Java Visual Editor
An annotation is used to associate information with a program element. Annotations can be used in classes, fields, methods, parameters, local variables, constructors, enumerations, and packages. To add annotations in your Java code: declare the annotation, create a function, and then add your annotations.
When you start adding an annotation, Member Insight (Ctrl+Space) displays a list of options (fields, members, classes) based on the statement context. Parameter Insight (Ctrl+Shift+Space) displays information about the annotation like the names of the elements of the annotation type, the default values, and the created values. It also highlights the element currently under the cursor in the annotation.
For more information see How to Add Documentation Comments.
You can hold down the Shift key and then hover over a variable or method to show its definition in a ghost window. This feature makes it convenient to quickly view code without moving cursor focus from your current code.
Figure 7-1 Code Peek
While dragging the vertical scroll bar, a small tip window appears next to the bar, revealing the methods that are visible or partially visible on screen. This enables you to more easily see what methods are in view while quickly scrolling. You can also see the name of the method whose beginning is not immediately in view.
An InfoTip is a pop-up window that reveals additional detail about an item in the application, for example, text in the Java Source Code editor and the overview gutter. You display the InfoTip by pointing or hovering over the item with your mouse cursor. It remains visible until you move the mouse away or click elsewhere in the UI.
Figure 7-2 InfoTips
To search incrementally, from the main menu choose Search > Incremental Find Forward or Search > Incremental Find Backward. Begin typing in the dialog that displays. As you type, the cursor jumps to the next instance of that particular letter combination, either forward or backward. The search does not support wildcards.
Shortcut keys, or accelerators, are combinations of keys that you can use to navigate or to perform certain operations using the keyboard instead of the mouse. You can select from a variety of predefined keymaps or define your own accelerators.
To view or change existing accelerators, to define new accelerators, or to load preset keymaps, from the main menu choose Tools, then Preferences to open the Preferences dialog and then navigate to the Shortcut Keys page. To view or change accelerators for the editor, select Code Editor from the Category list.
Note that block commenting is indicated by Toggle Line Comments. It is defined in the default keymap as Ctrl-Shift-Slash or Ctrl-Slash.
For more information, see Keyboard Navigation in .
While bookmarking code:
You can see a list of all bookmarks you have created in a Bookmarks window. This window appears when you click the Go to Bookmark icon. This window also displays the line number and method name that contains the bookmark.
Figure 7-3 Go to Bookmark Icon
You can create numbered bookmarks using the keyboard shortcut Ctrl+Shift+<number>. You can quickly navigate to that bookmark by pressing Ctrl+<number>.
For more information, see How to Set Bookmarks in Source Files.
To navigate to the source for any identifier in an open Java file, right-click on the identifier you would like to browse and choose Go to Declaration. Alternatively, you can hold down the Ctrl key and click on an identifier to navigate to its source. If the source is not available, JDeveloper will reverse-engineer the class file. You may browse imported classes and interfaces, member fields and methods, and local variables. If you are browsing a method or constructor invocation, this declaration search will resolve the types in order to determine the correct method or constructor invocation. For instance, the following code revokes the declaration search at SetText. It brings up the source code for javax.swing.JButton
, with the SetText()
method displayed.
import javax.swing.JButton ... JButton b1 = new JButton(); ... b1.SetText: ('OK');
If the identifier cannot be browsed or if there is nothing at that cursor position, this search command on the context-sensitive menu will be disabled. If JDeveloper is unable to locate the appropriate location to jump to or if the identifier cannot be browsed due to access restrictions (for example, private members), the Java Source Editor's status bar will display a message indicating so.
Code templates are sections of pre-written code that can be conveniently inserted into source file to avoid typing it in manually. Templates can intelligently modify the inserted code to suit its surrounding code, and imports required by code templates are automatically imported.
A complete list of all code templates is available in the Code Editor Help. To edit or create code templates, or to view or change accelerators, from the main menu choose Tools > Preferences to open the Preferences dialog and then navigate to the appropriate page.
For more information, see How to Use Code Templates.
You can customize the behavior of the Java Source Editor using the Preferences Dialog. You can also use the Preferences Dialog to specify settings for the general source editing environment. For more information, see How to Set Preferences for the Source Editor.
To set the options for Code Insight as it applies to Java:
JDeveloper enables you to set comment and brace-matching options for the Java source editor. For example, you can choose to add leading and closing asterisks as you add new lines either in multi-line Java comments or in Javadoc comments.
To set the options for Java comment and brace matching in the source editor:
Note that block commenting is an accelerator function. In the default keymap, use Ctrl+Shift+/ or Ctrl+/ to block-comment Java code.
You can set options to sort import statements in the Java Source Editor.
To set the options for sorting import statements:
You can use the Tools > Preferences dialog to select a profile that determines the style of code shown in the Java Source Code editor. The coding style determines Java Code conventions such as formatting, how import statements display in code, variable names, and member order.
To select a coding style for the Java Source Code editor:
You can edit an existing coding style and make it available as a selectable Profile option on the Code Style page. You can also import an existing code style profile from an XML file.
To edit an existing code profile:
You can create a custom coding profile using an extension, then set it as the default for a role, for example, developer, using the extension.xml
file. For more information, see "Introduction to Developing Oracle JDeveloper Extensions" in Oracle Fusion Middleware Developing Extensions for Oracle JDeveloper.
To set a default coding profile using an extension:
The Java Source Editor displays Java source files, and facilitates editing of Java code. Icons that perform various features are located at the top of the Java Source Editor, as described in Table 7-1.
Table 7-1 Toolbar Options
Icon | Name | Description |
---|---|---|
|
Quick Outline |
Click to display a tree of the available methods and fields of the current class and its super classes. Clicking this icon brings up the Quick Outline window (for more information, see Using the Quick Outline Window). This window floats just above the code and contains a tree of the available methods and fields of the current class and its super classes. You can instantly start typing in a filter field to reduce the visible items, allowing quick and easy selection for navigation to the desired place |
|
Code Highlight |
Click to highlight all instances of the code component that the cursor is currently placed on. |
|
Clear All Highlighting |
Click to clear all highlighting. |
|
Surround |
Click to surround the currently selected block of text in the Java Source Editor with a coding construct, using the Surround With dialog. |
|
Generate Accessors |
Click to insert get and set methods into a class, using the Generate Accessors dialog. |
|
Override Methods |
Click to override inherited methods for the class in focus. |
|
Implement Interfaces |
Click to modify a target class to implement one or more interfaces, or to make a target interface extend one or more other interfaces, using the Implement Interface dialog. |
|
Reformat |
Click to apply source formatting to your code. |
|
Toggle Bookmark |
Click to insert or remove a bookmark on the line of code currently in focus. |
|
Go to Next Bookmark |
Click to place the cursor at the next bookmark. |
|
Go to Previous Bookmark |
Click to place the cursor at the previous bookmark. |
|
Show Selected Element Only |
Click to view only one particular element in the editor. You can use this feature to tightly focus on a method, class, inner class, or field declaration. A message at the bottom of the file reminds you that the Show Selected Element mode is currently active. |
|
Block Coloring |
Click to activate block coloring. You can use this feature to highlight blocks of code for better readability. Coloring preferences can be set using the Preferences Dialog. |
Clicking the Quick Outline Toolbar icon (Figure 7-4) to the right of the Find field in the Java source editor displays the Quick Outline window shown in Figure 7-5.
Figure 7-4 Quick Outline Icon
This window floats just above the code and contains a tree of the available methods and fields of the current class and its super classes. You can instantly start typing in a filter field to reduce the visible items, allowing quick and easy selection for navigation to the place.
Figure 7-5 Quick Outline Window
Table 7-2 lists the available icons and options.
Table 7-2 Quick Toolbar Icons
Icon | Name | Description |
---|---|---|
|
Show Methods |
Click to display methods and constructors. The default is methods, fields, and static members all displayed. |
|
Show Fields |
Click to display fields. The default is methods, fields, and static members all displayed. |
|
Show Static Members |
Click to display static members. The default is methods, fields, and static members all displayed. |
|
Show Public Members Only |
Click to display only public members. The default value is deselected. |
|
Show Inherited Member |
Click to display only inherited members. |
|
Sort Alphabetically |
Click to sort class members alphabetically. The default value is deselected. |
|
Sort by Type |
Click to sort class members first by type (in this order: constructors, methods, fields, inner classes), and then alphabetically within those categories. The default value is selected. Click the down arrow next to Sort Alphabetically to view the option. |
|
Sort by Access |
Click to sort class members first by access modifier, and then alphabetically within those categories. The default value is deselected. Click the down arrow next to Sort Alphabetically to view the option |
|
Show Detail Window |
Click to open the Show Detail window for the selected item in the Quick Outline window. In the Show Detail window, click the Documentation tab to view the package containing the item. In the Show Detail window, click the Code tab to see its definition in the source file. |
The Java UI Visual Editor displays the visual components of a user interface in editing mode. For more information, see Editing with the Java Visual Editor .
Note:
You can use the Java Visual Editor for Swing/AWT Applications only.
Use Swing and AWT JavaBeans components to assemble the user interface (UI) for a Java application or applet. You construct the UI in the Java Visual Editor by selecting JavaBeans from the Components window, such as buttons, text areas, lists, dialogs, and menus. Then, you set the values of the component properties and attach event-handler code to the component events. Tools to visually design and program Java classes to produce new compound or complex component.
For more information, see About Java Swing UI Components and Containers.