<<

Published October, 1998 Copyright © 1998 by NetBeans, Inc. This document is being furnished by NetBeans, Inc. for information purposes only to licensed users of the NetBeans Developer 2.0 software product and is furnished on an “AS IS” basis, that is, without any warranties whatsoever, express or implied. NetBeans is a registered trademark of NetBeans Corporation. Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. UNIX is a registered trademark in the United States and other countries, exclusively licensed through X/Open Company, Ltd. Other brand and product names are trademarks of their respective holders. The software described in this document is furnished under a license agreement. The software may be used only in accordance with the terms of that license agreement. THIS PUBLICATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES ARE PERIODICALLY ADDED TO THE INFORMATION HEREIN; THESE CHANGES WILL BE INCORPORATED IN NEW EDITIONS OF THE PUBLICATION. NETBEANS CORPORATION MAY MAKE IMPROVEMENTS AND/OR CHANGES IN THE PRODUCT(S) AND/OR THE PROGRAM(S) DESCRIBED IN THIS PUBLICATION AT ANY TIME. Table of Contents

Preface...... 10 1. Audience...... 10 2. Document Structure...... 10 3. Conventions Used In This Document...... 10 4. Contact Information...... 11 4.1. Registration Number Problems...... 11 4.2. Online Technical Support ...... 12 4.2.1. Newsgroups ...... 12 4.2.2. The FAQ...... 12 4.2.3. Virtual Machines...... 12 4.2.4. Contacting Technical Support...... 12 I. Welcome to NetBeans Developer...... 14 1. Introduction ...... 15 1.1. Java ...... 15 1.2. NetBeans Developer 2.0 ...... 16 1.2.1. Product Overview ...... 16 1.2.2. Features...... 16 1.3. NetBeans Enterprise ...... 18 2. Concepts Behind NetBeans’ IDE ...... 19 2.1. IDE Should Incorporate Advanced Java Technology...... 19 2.2. Make IDE Freely Extendable ...... 19 2.3. Provide Multiple Development Options ...... 20 2.4. Make Development Intuitive ...... 20 2.5. Create Platform Independent Product...... 20 2.6. Strictly Adhere to Standards...... 21 II. Getting Started...... 22 3. Installing NetBeans Developer ...... 23 3.1. System Requirements ...... 23 3.1.1. Hardware on Intel 80x86 Platforms...... 23 3.1.2. Software...... 23 3.1.3. Installation ...... 23

2 3.2. Installation Formats ...... 24 3.3. Installation ...... 24 3.3.1. nbdev200.exe ...... 25 3.3.2. nbdev200.sh ...... 25 3.3.3. nbdev200.class...... 25 3.3.4. nbdev200.class and Macintosh Installations...... 27 3.3.5. NetBeans_Developer-2.0.XXX-Y.noarch.rpm ...... 27 3.4. UNIX Shared Multi-user Installations...... 27 4. User Interface...... 29 4.1. The Main Window ...... 29 4.1.1. Menus and Toolbars...... 30 4.1.2. Component Palette...... 30 4.1.3. Workspaces ...... 30 4.2. The Explorer ...... 30 4.2.1. Navigation...... 31 4.2.1.1. Explorer Toolbar...... 31 4.2.1.2. Default Actions...... 32 4.3. Property Sheet...... 32 4.4. The Editor...... 34 4.4.1. MultiWindow Functionality...... 35 4.4.1.1. Introduction ...... 35 4.4.1.2. Docking and Undocking Windows...... 36 4.4.1.3. Cloning Windows ...... 36 4.4.2. Working in Editor Panes...... 37 4.4.2.1. Using the Mouse...... 37 4.4.2.2. Clipboard Operations...... 37 4.4.2.3. Editor Abbreviations...... 37 4.5. Form Editor...... 38 4.6. Debugger Window ...... 39 4.7. Execution Window...... 40 4.8. Output Window...... 41 4.9. Built-In Web Browser...... 42 4.10. Popup Menus ...... 42 III. Working with NetBeans Developer...... 44

3 5. Fundamental Operations...... 45 5.1. Using Workspaces ...... 45 5.2. Exploring Objects ...... 46 5.2.1. Repository...... 46 5.2.1.1. Filesystems and the CLASSPATH...... 47 5.2.1.2. The Mount Point...... 47 5.2.1.3. Mounting New File Systems ...... 47 5.2.1.4. Working with Packages ...... 48 5.2.1.5. Working with Objects ...... 49 5.2.2. Templates...... 51 5.2.3. Control Panel ...... 52 5.2.4. Environment...... 52 5.2.4.1. Repository Settings...... 52 5.2.4.2. Main Window ...... 52 5.2.4.3. Workspaces ...... 53 5.2.4.4. Shortcuts ...... 53 5.2.4.5. Component Palette...... 53 5.2.4.6. Debugger...... 54 5.2.4.7. Processes...... 54 5.2.4.8. Actions...... 54 5.3. Creating New Objects...... 54 5.4. Using Templates ...... 55 6. Developing Java Classes...... 56 6.1. Exploring Java Objects ...... 56 6.1.1. Elements of Java Objects...... 56 6.1.2. Creating New Elements ...... 57 6.2. Editing Java Objects ...... 58 6.2.1. Layout of the Java Editor...... 58 6.2.2. Layout of the Java Editor...... 58 6.2.3. Integration with Other Components ...... 58 6.3. Compiling Java Objects...... 59 6.3.1. Compiling Single Classes...... 59 6.3.2. Compiling Packages ...... 59 6.3.3. Shortcuts ...... 60

4 6.4. Executing Java Objects...... 60 6.4.1. Running Applets, Specifying Applet Viewer ...... 60 6.4.2. Running Applications ...... 61 6.5. Debugging Java Objects ...... 62 6.5.1. Breakpoints...... 62 6.5.2. Threads ...... 63 6.5.3. Watches...... 63 6.5.4. The Debugging Session ...... 63 6.6. Designing Visual Forms ...... 64 6.6.1. Creating a New Form, Opening Form Editor ...... 64 6.6.2. Form Editor Basics ...... 65 6.6.2.1. Adding New Components...... 65 6.6.2.2. Selecting Components ...... 66 6.6.2.3. Connection Mode ...... 67 6.6.2.4. Copying Components ...... 67 6.6.2.5. Reordering Components ...... 68 6.6.3. Working with Layouts ...... 68 6.6.3.1. Setting and Changing Layout Managers ...... 68 6.6.3.2. NetBeans’ Support for LayoutManagers...... 69 6.6.3.3. Layout Managers Summary...... 72 6.6.3.3.1. AbsoluteLayout ...... 72 6.6.3.3.2. BorderLayout...... 73 6.6.3.3.3. FlowLayout...... 73 6.6.3.3.4. GridLayout...... 73 6.6.3.3.5. CardLayout ...... 73 6.6.3.3.6. GridBagLayout ...... 74 6.6.3.3.7. BoxLayout ...... 74 6.6.3.4. Support for Custom Layout Managers ...... 74 6.6.4. Working with Source Code...... 75 6.6.4.1. Non-editable Blocks ...... 75 6.6.4.2. External Modifications ...... 75 6.6.5. Form Editor Modes...... 76 6.6.6. Events ...... 77 6.6.7. Using the Connection Wizard...... 78

5 6.6.8. Menu Editor...... 81 6.6.8.1. Creating a Menu Bar...... 81 6.6.8.2. Creating a Popup Menu ...... 83 6.6.8.3. Adding Menu Items ...... 83 6.6.8.4. Menu Item Events...... 84 6.6.9. Components with Special Support ...... 85 6.6.9.1. JScrollPane, ScrollPane ...... 85 6.6.9.2. JTabbedPane ...... 85 6.6.9.3. JTable, JList ...... 87 6.6.9.4. MDI Applications: Using JDesktopPane and JInternalFrames...... 87 6.6.9.5. JSplitPane ...... 88 7. Advanced Operations...... 89 7.1. Using the BeanWizard...... 89 7.2. Adding JavaBeans to the IDE...... 91 7.2.1. Standard Method...... 91 7.2.2. Alternate Method...... 91 7.2.3. Automatic Method...... 92 7.3. Customizing JavaBeans ...... 93 IV. Customizing NetBeans Developer ...... 95 8. Control Panel ...... 96 8.1. System ...... 96 8.2. Output Window...... 96 8.3. Property Sheet...... 97 8.4. Extensions...... 98 8.5. Internal ...... 98 8.6. External Compiler...... 98 8.7. Internal Execution...... 99 8.8. External Execution...... 99 8.9. Debugger...... 100 8.10. Java Objects ...... 100 8.11. Form Objects ...... 101 8.12. Applets...... 102

6 8.13. HTTP Server...... 103 8.14. Network Options...... 103 8.15. Java Editor, Text Editor, HTML Editor ...... 104 9. Customizing the Environment ...... 106 9.1. Customizing Menus and Toolbars ...... 106 9.2. Customizing Shortcuts...... 107 9.3. Customizing the Component Palette ...... 107 9.4. Customizing Workspaces...... 108 A. Default Keyboard Shortcuts ...... 110 A.1. Global Shortcut Keys...... 111 A.2. Form Editor Shortcut Keys ...... 111 A.3. Editor Shortcut Keys...... 112 A.4. Explorer Shortcut Keys...... 114 A.5. Window Shortcut Keys ...... 115 A.6. Build Shortcut Keys...... 115 A.7. Debugger Shortcut Keys ...... 116 B. Default Editor Abbreviations ...... 117 C. Main Window Menus and Toolbars ...... 120 C.1. Menus...... 120 C.1.1. File Menu ...... 120 C.1.2. Edit Menu...... 120 C.1.3. View Menu...... 121 C.1.4. Build Menu ...... 121 C.1.5. Debug Menu...... 122 C.1.6. Tools Menu ...... 122 C.1.7. Window Menu...... 122 C.1.8. Help Menu ...... 123 C.2. Toolbars...... 123 D. Actions...... 126 Recommended Reading...... 131

7 List of Tables

5-1. Package Popup Menu Actions...... 48 5-2. Object Types...... 49 5-3. Common Object Actions...... 51 6-1. Document icons of Java Objects ...... 56 6-2. Java Object Elements ...... 57 6-3. Basic Form Types Supported by NetBeans...... 64 6-4. Form Editor Modes ...... 76 8-1. Output Window Properties ...... 96 8-2. Property Sheet Properties ...... 97 8-3. Internal Compiler Properties ...... 98 8-4. External Compiler Properties ...... 99 8-5. Internal Execution Properties ...... 99 8-6. External Execution Properties...... 99 8-7. Debugger Properties ...... 100 8-8. Java Objects Properties...... 100 8-9. Form Objects Properties...... 101 8-10. Applets Properties ...... 102 8-11. HTTP Server Properties ...... 103 8-12. Network Options Properties ...... 103 8-13. Common Editor Properties...... 104 A-1. Naming Convention for Function Keys...... 110 A-2. Naming Convention for Modifier Keys...... 110 D-1. Data Actions ...... 126 D-2. Edit Actions...... 126 D-3. System Actions...... 127 D-4. View Actions ...... 128 D-5. Build Actions...... 128 D-6. Debugger Actions...... 129 D-7. Form Actions...... 130

8 List of Figures

4-1. The Main Window with Windows Look and Feel ...... 29 4-2. The Explorer with Metal Look and Feel ...... 30 4-3. Explorer with its Property Sheet Pane...... 33 4-4. The Editor...... 34 4-5. Form Window...... 38 4-6. Component Inspector ...... 38 4-7. The Debugger Window...... 40 4-8. The Execution Window ...... 40 4-9. The Output Window ...... 41 6-1. Component Palette Indicating Add Mode...... 66 6-2. Selection Mode...... 66 6-3. Connection Mode ...... 67 6-8. Creating MenuBar ...... 81 6-9. Menu...... 82 6-10. Adding Menu Items...... 83 6-11. Support for JTabbedPane...... 86 C-1. Main Window Toolbar - Top Row ...... 124 C-2. Main Window Toolbar - Bottom Row ...... 124 C-3. Main Window Toolbar - New Window icons ...... 124 C-4. Main Window Toolbar - Form Editor icons...... 125

9 Preface

This book describes how to develop with and customize NetBeans Developer version 2.0.

1. Audience

This document is intended for software engineers who will implement Java applications and applets with NetBeans Developer. It is assumed that the reader has a general knowledge of Java.

2. Document Structure

This book is divided into four parts. The first is an introduction to the concepts behind the NetBeans Developer 2.0 Integrated Development Environment (referred to as the NetBeans IDE, or IDE for short). The second part describes major components and features of the IDE’s user interface. The third demonstrates practical use of these features. The fourth gives a breakdown of some of the fundamental concepts and ideas behind the architecture of the NetBeans IDE, as well as covering some advanced customization and modification of the IDE itself.

3. Conventions Used In This Document

The following conventions are used in the text:

• Boldface

• Items you can select, such as buttons and menu choices.

• New terms the first time they are used.

• Italics

• Method names in general discussion.

10 Preface

• Text that you can enter.

• Monospace

• Examples of Java code.

• File names. Look & Feel: Depending on your platform, the appearance of the IDE GUI (Graphical User Interface) may appear quite different from the screenshots shown here. By default the IDE launches in the "Windows Look & Feel" when running on a Windows platform, or the "Metal" Look & Feel on all other platforms. Most screenshots in this document were taken using the Windows Look & Feel. The Look & Feel can be set via the View | Look & Feel menu—although, please note that you won’t be able to use the Windows Look & Feel on non-Windows platforms. “Press Return” means that you should press the Return key on your keyboard. If you don’t have a Return key, the Enter key should work. Keys like F5 and F9 refer to those function keys (also sometimes labeled PF5 and PF9). “Ctrl” refers to the Control key. A set of keystrokes joined with “+”, like Ctrl+F9, means you should press the first key (here, Ctrl), hold it down, and press the second key (here, F9).

4. Contact Information

For the latest news and information, please check the NetBeans website http://www.netbeans.com/ If you have any general queries about NetBeans products, pricing and release schedules, please mail info@.com. Your feedback is always welcome. Please mail any relevant comments you might have to [email protected].

4.1. Registration Number Problems

If you have purchased NetBeans Developer, and you’ve lost or are having problems with your registration code, please mail [email protected]. Try to include as

11 Preface

much relevant information as possible including your full name, the approximate date you ordered NetBeans, and the email address you used when ordering.

4.2. Online Technical Support

If you’re having problems with NetBeans, please make use of the following online resources:

4.2.1. Newsgroups The NetBeans newsgroups are buzzing with discussion on all aspects of NetBeans, from technical support issues to custom extensions. By using this public forum, you have access to the whole of the NetBeans community worldwide. The NetBeans Support Team regularly read and post to these groups. There is also a wealth of knowledge in previous postings. See http://www.netbeans.com/newsgroups.html for details of how to configure your newsreader to use the NetBeans newsgroups.

4.2.2. The FAQ Please check the FAQ (Frequently Asked Questions list), which covers all common problems with installation, startup, and running NetBeans. This list is updated regularly as new issues come to light. The FAQ can be found at http://www.netbeans.com/faq.html.

4.2.3. Virtual Machines Check you are using a supported JVM. Known, working JVMs are listed on the JVMs page of the website, at http://www.netbeans.com/jvms.html.

4.2.4. Contacting Technical Support If you wish to contact technical support, please make use of the online Support Request form. Please note you will need the username and password you received when you registered on the NetBeans website to access the Support Request Form. To ensure the fastest possible resolution to your request, please fill out all required fields on the form—in particular, the System Information field is crucial. Without this information

12 Preface

the NetBeans Support Team are unable to process your request. Priority Support: While the NetBeans technical support team do respond to every request they receive, by purchasing NetBeans Developer 2.0 you ensure priority support. If you have purchased NetBeans, please use your 8 digit registration code when requesting support, and your request will be given the highest priority. The support request form can be found at http://www.netbeans.com/developer/support_request.html.

13 I. Welcome to NetBeans Developer This short part introduces Java, NetBeans Developer 2.0, and NetBeans Enterprise. Chapter 1. Introduction

1.1. Java

When the first generation of Java appeared on the development horizon in 1995, it was generally regarded as a language for creating animated applets and small web-based applications useful for the newly exploding Internet. Since then, the second generation of Java has arrived, and it is beginning to be seen as a much more robust solution that developers can use to create powerful, distributed applications. As such, the Java software industry is in the midst of a stage of extremely rapid growth. There are now close to 750,000 Java developers, and this number is expected to double over the next four years. Corporate investment in Java technology-based information systems is on the rise, with a 75% increase from present levels predicted over the next two years. NetBeans believes that there are two primary forces driving this growth: 1. The need for information from “everywhere”: With the explosion of the Internet, corporate and individual expectations on the availability and reliability of information have increased almost as fast. This information may be stored in a legacy mainframe at headquarters, a database at a supplier, or one of a thousand different types of servers spread out across the world. 2. The need for applications “everywhere”: Instead of electronic devices converging into the PC, there appears to be a steady growth in the number of non-PC peripherals. Due to advances in semiconductor performance, these products are extremely powerful and able to support an operating system and run a variety of applications. Examples include personal digital assistants, cell phones, network computer, digital set top boxes, etc. But despite all this interest and potential, Java as a language and platform is still in its infancy and has a lot of maturing to do before it reaches the level of acceptance we believe is possible. Today there is support for graphical users interfaces (Swing), database connectivity (JDBC), application servers (EJB), and distributed computing

15 Chapter 1. Introduction

(RMI). Tomorrow, these will all be significantly more advanced, extensive support for embedded systems will be available, and a host of new technologies generated around the world will be created beyond what we know is possible today. NetBeans was established to meet the challenges and dynamics of Java now and in the future. We want to help developers build the most advanced Java applications, in a very flexible and intuitive way. Developer 2.0 is the first step in this ongoing quest and we hope that you will find this documentation useful in your endeavors. The NetBeans Team, [email protected]

1.2. NetBeans Developer 2.0

1.2.1. Product Overview NetBeans Developer 2.0 is a full-featured, cross-platform Java technology IDE. It combines support for all stages of Java application development including visual design, coding, compiling, and debugging in a single visual-programming package. It runs on all platforms that support JDK 1.1.x, including Windows 95/98/NT, Linux, Solaris, OS/2, HP-UX, AIX, SGI Irix, Apple Macintosh and others. The IDE is based on JFC and JavaBeans Components, and all parts of the IDE are actually themselves JavaBeans.

1.2.2. Features User Interface:

• Completely customizable menu, toolbar and shortcuts

• Pluggable Look & Feel

• Multiple virtual workspaces Form Editor:

• “Live Java” JavaBeans-based form editor with support for both AWT and JFC components

16 Chapter 1. Introduction

• Integrated JFC components

• Full JavaBean support

• Full support for layout managers

• Connection Wizard

• Applet generation support

• Integration of third-party JavaBeans components Explorer:

• Browse JAR, ZIP FileSystems

• Compile All / Build All: recursively compile all sources in a package

• Java source parsing

• Support for Java introspection on classes without sources

• Methods and properties from parsing or introspection visually exposed

• User templates Debugger:

• Integrated visual debugger with multi-thread debugging support

• Full support for breakpoints, watches, locales and threads Editor:

• Text editor with syntax coloring JavaBean Wizard:

• Generate Beans in minutes Other:

• HTML browser

• Built-in HTTP lightweight server for project and source-code publishing

• Support for third-party modules

17 Chapter 1. Introduction

• International application supported - Unicode enabled

1.3. NetBeans Enterprise

In late Q4 of 1998, NetBeans will release a Beta version of its Enterprise IDE. The Enterprise version will extend the functionality and power of the Developer version tremendously. It is intended for multi-user, multi-platform development environments. Some of the additional features found in the Enterprise Edition include:

• Version control: Users can share File systems, debug remotely, access source control systems.

• Modular architecture: there will be Open APIs available for the integration of third party modules

• Support for Database connectivity (JDBC), Enterprise Java Beans (EJB), distributed computing (RMI)

• Support for custom compilation steps: rmic, javacc

• Advanced Editor Features: intelligent keyword/class/variable name, completion, class browser This documentation does not cover the Enterprise Edition. For more information on the Enterprise Edition, please check the NetBeans website.

18 Chapter 2. Concepts Behind NetBeans’ IDE

We took a unique approach to IDE by writing the entire IDE in Java and basing the architecture on JavaBeans. The result is an IDE that embodies the Java metaphor and provides a distinctive, Java-based experience. The IDE takes advantage of the built-in functionality of Java and incorporates advanced Java features such as Swing. The internal structure is easily configurable and extensible and the IDE runs independent of platform.

We also recognize that a broad range of developers will use the IDE and, invariably, attack problems from different directions. We addressed this by incorporating a wide range of developer options.

Below, we outline the major concepts and beliefs that went into the development of Developer 2.0.

2.1. IDE Should Incorporate Advanced Java Technology

Java is rapidly evolving. Sun frequently makes new JVMs available, which are followed by ports on multiple platforms. The standards and implementations for Swing, JDBC, RMI, etc. are also continually advancing. Sun and other Java development companies continually launch completely new technology. Java developers demand that these be incorporated rapidly into their development tools. NetBeans was the first IDE to be constructed from JavaBeans, which allows easy platform extension. NetBeans was the first IDE to provide support for advanced visual development of both Swing and AWT applications and has consistently supported JDKs shortly after their release. In the Enterprise release, NetBeans will support JDBC, RMI, EJB, and incorporate technology from other Java vendors.

19 Chapter 2. Concepts Behind NetBeans’ IDE

2.2. Make IDE Freely Extendable

NetBeans will not be able to integrate all the technology that developers desire. We want to allow users to easily extend their environment and capabilities easily and effectively. In this release, this is inherent in the way JavaBeans can be integrated into the IDE (as with the KLGroup’s JClass Chart Lite components). In subsequent releases, the IDE will itself be constructed from modules with publicly available APIs. NetBeans will also integrate third-party components this way. Among the first modules to be added will be Cloudscape’s embeddable Java database.

2.3. Provide Multiple Development Options

Not all developers will develop an application in a similar manner. NetBeans allows developers to assemble and edit code and customize their environment in a variety of ways. Users can freely customize Menus and Toolbars, shortcuts, the Component Palette, and Workspaces. Also, as an example of the options NetBeans provides, the developer can either assemble Java code in the Form Editor, by manual coding, or by using NetBeans’ numerous templates.

2.4. Make Development Intuitive

NetBeans approaches all object types (configuration objects, various data types, classes and their fields/methods, beans, etc.) in a unified and consistent manner. Complete functionality of any of these items is available in a tree structure accessible from the Explorer, and all operations with objects can be performed from their popup menus, an easy-to-access toolbar or from the main menu.

2.5. Create Platform Independent Product

Although a single developer might work on a single, specific platform, many developers and development teams work on multiple platforms. Platform neutrality enables developers to work together, each on their own platform of choice, to build

20 Chapter 2. Concepts Behind NetBeans’ IDE

products that will run in a consistent way in any environment. Because it is written in Java, NetBeans can run on all platforms that support JDK 1.1.x, including Windows 95/98/NT, Linux, Solaris, HP-UX, OS/2, and others.

2.6. Strictly Adhere to Standards

NetBeans is based on Sun Microsystems’ Java implementation. It generates Java code that conforms to Sun’s 100% Pure Java standard, meaning that it can be run on every Java 1.1.x VM-enabled platform. NetBeans fully supports the JFC library for generating the application GUI and it allows extension of its native component palette with any JavaBean-compliant class.

21 II. Getting Started This Part is designed to help you get NetBeans running on your machine and familiarize you with the basic features and functionality of the IDE. The first Chapter provides installation instructions for Developer 2.0 with specific details for installation on different platforms such as Windows, UNIX, Mac, etc.. The next Chapter gives a tour through each of the major parts of the IDE: User Interface and Main Menu, Explorer, Property Sheets, Source Editor, and Form Editor.

22 Chapter 3. Installing NetBeans Developer

This Chapter describes installation of the NetBeans IDE. Before installation, please check the system requirements below.

3.1. System Requirements

3.1.1. Hardware on Intel 80x86 Platforms Minimum configuration : Windows 95/NT: P133 processor, 48MB RAM, 16MB free disk space. Recommended configuration : Windows 95/NT: P200 processor, 96MB RAM. Due to the memory intensive requirements of the Linux JVM, this platform generally requires more RAM than Windows platforms.

3.1.2. Software NetBeans Developer 2.0 requires a Sun compatible Java Virtual Machine, version 1.1.5 or later where available, to run. The 1.1.7 JDK for Windows is strongly recommended on that platform. The latest JDK is available for download from http://java.sun.com/products/jdk/1.1/. Linux users should use the 1.1.6 JDK available from http://www.blackdown.org/. NetBeans does not run well with other currently available Linux VMs. The JVMs page of the NetBeans website lists all recommended VMs and versions for many platforms, and provides links to download sites for these VMs where available. Please check the NetBeans JVMs page for the latest information: http://www.netbeans.com/jvms.html.

23 Chapter 3. Installing NetBeans Developer

3.1.3. Installation The installation procedures themselves require a 1.1 JVM installed on your system to run successfully. If you do not yet have a 1.1 VM, you should install one prior to running the NetBeans installation.

3.2. Installation Formats

There are several different installation formats of NetBeans Developer 2.0 available. The software in each of these formats is identical; it is merely bundled in different InstallShield formats for ease of use on different platforms. All formats require a 1.1 JVM installed on your system to install correctly. Available formats are:

• nbdev200.exe - a standard InstallShield Win32 self-extracting executable

• nbdev200.sh - a self-extracting Unix archive

• nbdev200.class - a java class installation

• NetBeans_Developer-2.0.XXX-Y.noarch.rpm - Red Hat Package Manager (rpm) distribution for Red Hat Linux (XXX indicates build number and Y indicates package version) For most platforms, there is a choice of installation format. The nbdev200.class java installation will run on any platform with a 1.1 JVM installed - if you are unsure which format to use, use this one. A summary of recommended formats is given below:

• Windows 95 / 98 / NT: nbdev200.exe

• Red Hat, Caldera and SUSE Linux: NetBeans_Developer-2.0.XXX-Y.noarch.rpm

• Other Linux and Unixes: nbdev200.sh

• OS/2: nbdev200.class

• Macintosh: nbdev200.class (see Macintosh notes below)

• Other: nbdev200.class

24 Chapter 3. Installing NetBeans Developer

3.3. Installation

Here are instructions for each installation format listed above.

3.3.1. nbdev200.exe

Double click the nbdev200.exe file you have saved to your system. This will decompress the InstallShield routine, which will then launch. Follow through the InstallShield wizard dialogs. The install routine will attempt to locate a 1.1 VM on your system; if it fails to locate one, you must browse to locate one before continuing. Once complete, you will have a shortcut to NetBeans Developer 2.0 on your Desktop. On your Start Menu, you’ll also have a NetBeans entry containing shortcuts to NetBeans Developer, the README.txt file, and the NetBeans website.

3.3.2. nbdev200.sh

Note that the instructions in this section are only for single-user installations. To install for multiple Unix users, see Section 3.4 below. Open a command prompt. Change working directory to the location where you’ve saved the nbdev200.sh file. Launch the installation by typing the command:

sh nbdev200.sh

Before decompressing, nbdev200.sh will attempt to locate a 1.1 JVM on your system. A menu listing any found, and the option to specify another VM will be shown. Once one of these is selected, it is used to launch the InstallShield routine. Follow through the InstallShield Wizard dialogs. Once complete, use the launch script netbeans.sh in your installation directory to launch NetBeans.

3.3.3. nbdev200.class

25 Chapter 3. Installing NetBeans Developer

Macintosh users, please see Section 3.3.4. Open a command prompt, and change working directory to the location you have the nbdev200.class file saved. If you have a CLASSPATH set, and it does not include the current directory, you will need to add the current directory to your existing CLASSPATH. If you do not have a CLASSPATH set, skip to the next step. To check whether you have a CLASSPATH currently set, type “set” (without the quotes) at a command prompt. If you see CLASSPATH listed, you have a CLASSPATH setting.

• To add the current directory to your CLASSPATH on a Windows machine, type: set CLASSPATH=.;%CLASSPATH%

• On a Unix machine with a Bourne-type shell (which typically gives a $ prompt), type: CLASSPATH=.:$CLASSPATH;export CLASSPATH

• On a Unix machine with a C-type shell (which typically gives a % or > prompt), type this command: setenv CLASSPATH .:$CLASSPATH

Next, on all platforms, type the following command (and note that you should not include the “.class”):

java nbdev200

This assumes you have a 1.1 VM in your path. If you do not, you must specify the full path to the java interpreter executable—for example:

C:\TEMP>C:\jdk1.1.7\bin\java.exe nbdv20b3

This will initiate a standard InstallShield installation routine. Simply follow through the dialogs as normal.

26 Chapter 3. Installing NetBeans Developer

Once complete, use the launch script in your installation directory to launch NetBeans. If you are installing nbdev200.class on a Windows machine, you will have shortcuts for launching NetBeans under your Start Menu.

3.3.4. nbdev200.class and Macintosh Installations To install nbdev200.class on the Macintosh, you will need JBindery (which is bundled with the MRJ SDK) to launch the .class installation. The MRJ SDK is available from http://devworld.apple.com/java/text/download.html. Simply drag and drop the nbdev200.class file onto your JBindery icon, and click Run. This will launch the InstallShield installation routine. Once the installation has completed, see the README.txt file in your NetBeans installation folder for details on launching.

3.3.5. NetBeans_Developer-2.0.XXX-Y.noarch.rpm Open a command prompt, and change working directory to the location you have the file saved. You must install the rpm format as the superuser (root user). From the command line, type a command like the following, where XXX is replaced by the current build number:

rpm -i NetBeans_Developer-2.0.XXX-Y.noarch.rpm

This will install NetBeans to /usr/local/netbeans and generate a launch script netbeans.sh in /usr/local/bin/. Assuming this directory is in your path, simply type netbeans.sh to launch NetBeans Developer 2.0.

3.4. UNIX Shared Multi-user Installations

With the exception of the rpm distribution, the installation procedures in the previous section are for single users only. Unix users may wish to create shared installations, such that multiple users may use the same installation of NetBeans. To do this, the installation routine must be run as the superuser (root) and the

27 Chapter 3. Installing NetBeans Developer

installation directory you specify should be a shared directory (for example /usr/local/netbeans). Once this installation is complete, each individual user who wishes to use NetBeans should do the following : 1. Create a NetBeans directory in your home directory, and copy the Development and system subdirectories from the shared installation to this new local directory. 2. Copy the netbeans.sh launch script from the installation directory to your home directory. Modify this script, and add the “-Dnetbeans.user” command line switch to the command line, pointing to your local NetBeans directory. For example, a user named foo with home directory /usr/home/foo/ creates a directory netbeans /usr/home/foo/netbeans/. The Development and system hierarchies are copied from the shared installation to this new local directory (/usr/home/foo/netbeans/Development/.....). The launch script netbeans.sh is copied from the shared installation to /usr/home/foo/. The java execution line of this script is modified to look something like the command below. Note the command below is broken into three lines for formatting reasons; the command in your startup script should all be entered on a single line.

java -Dnetbeans.home=$NETBEANS_HOME -Dnetbeans.user=/usr/home/foo/netbeans -mx40m com.netbeans.developer.Main

This can be customized as necessary.

28 Chapter 4. User Interface

The NetBeans IDE user interface is organized around its main segments: the Main Window, Explorer, Editor, Form Editor, Component Inspector, Debugger, Execution System display, and the Output Window. This default set of windows, Workspaces and tools can be adjusted freely to match the user’s preferences. Java is an object oriented programming language. The NetBeans user interface itself is also object oriented! This is an important difference between NetBeans and other IDEs. Most IDEs force you to remember the exact menu item or sequence of commands to perform an operation. In NetBeans, there are usually several ways to do the same thing—especially, by opening an object’s popup menu (typically, by right-clicking on the object) to see its properties and all operations available for the object. The NetBeans user interface offers different “looks” based on the platform being used. By default, the IDE launches in the “Windows” Look & Feel when running on a Windows platform and the “Metal” Look & Feel on all other platforms. It can then be adjusted to meet the developer’s preferences.

4.1. The Main Window

The Main Window is the first item opened when NetBeans is launched. The Main Window can be viewed as the “control center” of the IDE. All important operations and actions are accessible from this window. The Main Window can be broken into four separate groups of controls: the menus, the toolbar, the Component Palette, and the Workspace tabs. The Main Window also has a status line.

Figure 4-1. The Main Window with Windows Look and Feel

29 Chapter 4. User Interface

4.1.1. Menus and Toolbars

A listing of all menu items and toolbar operations is given in Appendix C, and specific operations are mentioned in pertinent sections. Note that menus and toolbar tools are context sensitive: they may be grayed out or unavailable, depending on which Window is currently active or which object is selected. Menu entries can be re-ordered and customized; see Section 9.1.

4.1.2. Component Palette

The Component Palette (shown in the right-hand half of Figure 4-1) is used in conjunction with the Form Editor to visually build forms. It consists of several tabs, each housing standard components and layouts.

4.1.3. Workspaces

NetBeans IDE uses the concept of Workspaces to manage windows and tools. On the lower left corner of the Main Window you will see a set of three Workspace tabs: Editing, Running, and Debugging. Each workspace contains a set of opened windows appropriate to different specific stages of the development cycle. Clicking on each of these tabs “flips” between each Workspace.

4.2. The Explorer

The NetBeans Explorer gives a unified view of all data objects and provides a starting point for many programming functions. Here, you can work with objects, organize your work, modify object properties, connect various data sources, and customize the NetBeans environment.

30 Chapter 4. User Interface

Figure 4-2. The Explorer with Metal Look and Feel

4.2.1. Navigation

When you first start NetBeans and open the Explorer, you will see a data hierarchy with five items. The root is the Desktop. Under it are the Repository, Templates, Control Panel, and Environment. Navigating the hierarchy in the Explorer is simple. Click on the plus sign (or button, if using the Metal Look & Feel) next to each item to expand the tree. Each tree node represents an object, and the object types are visually distinguished with document icons. See Table 5-2 for an overview of available object types. Right-click on any item to access its popup menu. This contains the context-sensitive set of actions and property settings available for that item. Depending on the selected object, the popup menu will contain the appropriate options with some enabled and others disabled.

4.2.1.1. Explorer Toolbar The Explorer toolbar presents icons for standard clipboard operations: cut, copy and paste. It also includes a Delete icon and the Property Sheet view toggle button. To see the name for each icon, hold your mouse cursor over it and a Tool Tip label will appear. As with the popup menu, the toolbar icons are context sensitive. When a top-level node such as Desktop is selected, for example, the cut and delete functions are not available—because the Desktop cannot be deleted or moved.

31 Chapter 4. User Interface

Almost all objects in the Explorer hierarchy have some associated properties. The toggle button in the Explorer toolbar expands the Explorer to show the properties associated with each object. These property sheets can also be accessed via the Properties command on each object’s popup menu.

4.2.1.2. Default Actions

In the Explorer view, double clicking on an item, or selecting the item and pressing the Return key, performs the default action on that object: opening it, opening its property sheet, or expanding it. If the default action has already been performed, pressing Return or double clicking reverses the action. The default action varies for each object type. The most common action is “show the object,” which opens the selected object in an Editor window. For example, double clicking on a Java Object opens the source in the Editor. Double clicking on a method or variable of some Java class, as displayed under a parent Data Object, opens the Editor and positions the cursor on the line where that method or variable is declared. The default action for objects that represent an environment setting is to show properties. Double clicking on a folder object, such as a top-level node, simply expands or collapses the subtree. Double clicking on a bytecode object opens an editor with the source code visible (if the source is available). Double clicking on an item in the Control Panel opens a property sheet for that item.

4.3. Property Sheet

The Property Sheet pane displays the properties of the selected items. These items may represent JavaBeans, components in the Form Editor or the IDE’s system objects. When multiple items are selected, the PropertySheet displays the properties that are common to all the selected items. The items may have multiple sets of properties, and in this case each set of properties is displayed on a separate tab. The Property Sheet also displays several toolbar icons; the first three are Sort by options. Listed properties can be sorted by name or type, or left unsorted, using these toggles. The next toolbar button enables filtering of properties by Accessibility, (read/writable), such that only writable properties are displayed. The right-most toolbar

32 Chapter 4. User Interface

icon invokes the Customizer. The Customizer is is a dialog which can be used for advanced customization of the item. This icon is context sensitive, and is only available for customizable objects. You can access an object’s property sheet by clicking the Property Sheet View icon in the Explorer (as shown in the Figure below) or by using the Component Inspector (see Figure 4-6).

Figure 4-3. Explorer with its Property Sheet Pane

The Property Sheet consists of pairs of name and value panels. Each line of the Property Sheet represents one property of one (or more if multiple objects are selected) item. A name/value pair may be disabled (grayed) if it represents a read-only property without a custom property editor. For JavaBean properties, the name of a property (in the left panel) is derived from the display name of the JavaBean and may be localized. Each name panel’s Hint window displays its Accessibility information and a short description for that property. Accessibility details are shown in parentheses (’r/w’, ’r/-’, ’-/w’ or ’No property editor’), and depend on the property and PropertyEditor. The description is derived from the shortDescription definition in the JavaBean. The value panel either shows a property value as text or paints a representation of it (as for a color property). Tool Tip hints for the Value panel display the type of property, such as java.awt.Color. Clicking on this area switches the Value panel into the Input

33 Chapter 4. User Interface

state, allowing the value of the property to be changed. Double-clicking a value toggles the value if there are just two possibilities (for instance, changing True to False)—or, if multiple values are possible, the value advances to the next possible (for instance, Black might change to Blue, then to Red, and so on for each double-click). Also, depending on the type of property, there are three methods of changing the value. You may edit the value as text, select from a pull-down list, or open a custom property editor (from the “...” button).

A custom property editor is a dialog designed for editing the value of a property. All changes are applied throughout the environment immediately—for example, changing the color of the background of the Java Editor will change not only any new Java Editor windows you open, but any that are currently open. A Custom propertyEditor dialog box contains Cancel, OK and Default buttons. The OK button closes the Dialog, and is shown only if the property is writable. The Cancel button reverts to the setting before the Property Editor was invoked, and the Default button sets the value to the default. The Default button is shown only for components in the Form Editor.

4.4. The Editor

The Editor is a fully featured text editor that is integrated with the Form Editor, Explorer, and Compiler/Debugger. It is the default viewer for all Java, HTML, and text objects. Each of these editors opens in a single window with multiple tabs: the MultiWindow. More advanced features include docking and undocking of documents, cloning windows, customizable abbreviations, and dynamic word correction. See Section 6.2 for examples of these functions and a guide to integration with other parts of the program, syntax coloring, keyboard shortcuts, and abbreviations.

34 Chapter 4. User Interface

Figure 4-4. The Editor

4.4.1. MultiWindow Functionality

The MultiWindow frame presents multiple editors as separate tabs in a single frame. It enables you to quickly and easily flip between these editors.

4.4.1.1. Introduction

Each MultiWindow tab has a popup menu of actions, available by right-clicking on the tab itself. When just one object is open, the options are Save, and Clone. If more than one Object is open, Undock and Close are also presented. Double-click a Java or text Data object in the Explorer to open the Editor. Now double-click a second Data Object and you will see it open as a new tab in the Editor. To flip between these objects, simply click the appropriate tab at the top of the Editor window. The currently visible object is identified by a highlighted tab. How the tab is highlighted depends on the Look & Feel in use—in the Metal Look & Feel, the tab is shaded a different color to the other tabs; in other Look & Feels the active tab appears “in front” of other tabs.

35 Chapter 4. User Interface

A modified file in the MultiWindow is marked with an asterisk ( * ) on its tab. If there are any unsaved modifications when the Editor is closed, a prompt will appear to save or discard changes, or cancel the operation. While the MultiWindow does enable quick and efficient access to more than one source, only one of those sources is visible at any one time. At times it is useful to view different sources simultaneously, side by side. The MultiWindow makes this possible via the “Undocking” of individual windows.

4.4.1.2. Docking and Undocking Windows

Any object open in the MultiWindow Editor can be Undocked, and presented in its own stand alone, independent Editor window. In this way you can simultaneously view separate sources, side by side. Undocked editors may also be Docked back to the parent MultiWindow Editor. Undocking a document from the MultiWindow opens this document in a completely separate, stand-alone Editor window. To Undock an active MultiWindow tab, select Undock Window from the Window menu on the Main Window. This action is also available on the tab’s popup menu: right-click on the tab itself, and select Undock. Note this option is only presented on the popup menu when more than one object is open in the MultiWindow. The active object will be removed from the original Editor window and will appear in a new instance of the Editor. This new Editor may be repositioned, resized, moved to another Workspace, even closed—all independently of the “Parent” Editor window. Position the Editor windows side by side to view sections of source simultaneously, or copy and paste code between windows. To “Dock” an Undocked Editor window to the parent Editor, make sure that the “Child” or Undocked Editor is the active window, and select Dock Window from the Window menu on the Main Window. The undocked window will close, and the source will open as a new tab in the Original Editor window.

4.4.1.3. Cloning Windows

It is often useful to view separate sections of the same source file simultaneously. This

36 Chapter 4. User Interface

Editor utilizes a “Clone” function to accomplish this. With the required source as the active tab, select Clone View from the Window menu of the Main Window. This action is also available by choosing Clone on the tab’s popup menu. A new tab will open in the MultiWindow, displaying the same file. Undock this new view of the source as described above to view different sections of the same source simultaneously.

4.4.2. Working in Editor Panes This section describes operations you can perform in the MultiWindow editor panes.

4.4.2.1. Using the Mouse The Editor uses standard mouse functions: click and drag the left mouse button to select a block of text, double click the left button within a word to select that word. Triple click to select an entire line.

4.4.2.2. Clipboard Operations Text may be moved to and from the clipboard using keyboard shortcuts or the popup menu. Once you have selected a block of text, right-click the mouse button to access Cut, Copy, Paste, and Delete. Alternatively, use Ctrl-c to copy, Ctrl-x to cut, and Ctrl-v to paste. Ctrl-z undoes any action.

4.4.2.3. Editor Abbreviations To simplify editing of Java sources there is a set of customizable abbreviations built into the editor that can be used to expand a pre-defined short text into a full word or a phrase. Defining abbreviations is useful for either long or frequently used Java keywords. To test it, simply type “pu” and press Space. The text will be expanded to “public”. To enter characters without expansion, type Shift+Space; that enters a space without checking for abbreviations. NetBeans’ default abbreviations shown below are available as a Java program in package examples/internal/Abbrev.java. To redefine the abbreviations, modify the source code and run the file. You may also may extend a series of letters to match other words in the same document

37 Chapter 4. User Interface

with the same prefix. After typing in a series of letters, press Alt+Shift+/ to find the previous instance of any word containing that prefix. You may do this repeatedly to find multiple matches in the document. To find instances of the prefix later in the document, use Alt+/.

4.5. Form Editor

The Form Editor lets you design an application visually. With your mouse and the Component Palette, place components such as buttons, scroll bars, and menus directly on the Form Window. As you do, NetBeans automatically generates the Java code to implement the components. (The code is visible in the source Editor window.) The Form Editor also uses your chosen Java Layout Manager, which controls the appearance of the components in a window, to control the layout in the Form Editor. If you choose a different layout manager or change its parameters, the Form Editor can show your changes immediately.

Figure 4-5. Form Window

The Form Editor has three parts: the Form Window, shown in the Figure above, the Component Inspector, shown below, and the source editor, which is opened in the MultiWindow. The Component Inspector shows a tree of components are displayed visually in the Form Window.

38 Chapter 4. User Interface

Figure 4-6. Component Inspector

The Component Inspector has two panels. The top panel shows the hierarchy of components in the currently-selected Form Window. The bottom panel, a Property Sheet, lists the attributes of the currently-selected object and also lets you edit them. The Form Editor has a powerful open design. It’s based on JavaBeans architecture, so any JavaBean can immediately be used for visual development. By using standard AWT/JFC components, generated forms do not depend on any proprietary code or components. No classes need to be bundled with your forms because the Form Editor generates code that is entirely independent of the IDE.

4.6. Debugger Window

The Debugger Window monitors breakpoints, watches and threads during a debugging session. Breakpoints provide the ability to break (pause) at certain points within the code during execution and examine the current state of the system. Watches can be used to monitor the values of variables used in the code during execution. You can also monitor all threads during execution, with access to a thread’s call stack, and local variables throughout the whole call stack.

39 Chapter 4. User Interface

Breakpoints, Watches and Threads are all presented on separate tabs in the Debugger window, along with a property sheet. In fact, this window is a “view” of the Debugger hierarchy presented in the Explorer, under Environment | Debugger. See Section 6.5 for a guide to using the Debugger.

Figure 4-7. The Debugger Window

4.7. Execution Window

The Execution Window provides a view of all applications currently being executed within the IDE. This window is actually a view of the Explorer hierarchy under Environment | Processes.

Figure 4-8. The Execution Window

By default, the Execution Window is opened on the Running Workspace. When no applications are running, it simply displays "No Processes Running". When an application or applet is running, it will be listed by name. Each currently running process is listed. As for all objects in the IDE, a displayed process has a popup menu. In this window, the menu contains just one item: Terminate Process. This allows you to

40 Chapter 4. User Interface

force termination of the selected process.

4.8. Output Window

The Output Window is a tab controlled window, displaying output from any component that produces output—such as the compiler or executor. Output from each component is presented on a separate tab: the Compiler tab, the Parser tab, Debugger tab, and the Executed Processes tab.

Figure 4-9. The Output Window

This window is not visible on first launching NetBeans, and will not be displayed until performing an action such as compiling a source or executing or debugging an application. By default, the Output Window opens automatically on compilation or execution, on the Running and Debugging Workspaces. The Compiler tab is visible after compiling a Java source: it displays compilation output. The output is color coded: errors are marked red, other text is blue. Double clicking an error line on this tab will shift focus to the Editor window displaying the source, highlight the incorrect line in red, and position the cursor at the exact location of the compilation error. The Parser tab displays the Parser output. Use and display of this tab is optional; you can enable it by setting the Parser Output Enabled property of Control Panel | Java Objects to true. The Debugger tab is split vertically into two panels. The left panel displays the output of the application being debugged. The right panel displays useful debugging information such as details of the application’s threads, threadgroups and breakpoints.

41 Chapter 4. User Interface

Any application currently being executed also has a separate Executed Processes tab in the Output Window. Its tab displays the standard output of the application. In fact the standard input of the application is also redirected here—this is the TextField at the bottom of the tab. There are two options for these application tabs: Reuse and Clear. These properties can be found under Control Panel | Internal Execution properties. If the Reuse property is set true, each individual application will use only a single output tab—that is, successive execution will not create new tabs. The second option, Clear, is useful only if Reuse is set true. If the Clear property is set true, the tab is cleared before reuse. An application’s output tab also provides a right-click popup menu, with options to Terminate Process and close the tab.

4.9. Built-In Web Browser

The NetBeans IDE includes a built-in full-featured Web Browser (HotJava) that is useful in both testing and providing easy access to online help sources. It enables standard browsing capabilities from within the IDE and is useful in reaching online help sources. The NetBeans tutorial, for example, uses the WebBrowser to display the tutorial’s HTML instruction pages. The built-in browser also allows you to test applets by running them directly in the IDE.

To open the WebBrowser Window, either select it under the View menu item on the Main Window, or hit Alt+5, the default shortcut. Once the browser is open, it operates like any simple browser. To load a page, type the URL in the Location field and press Return. The forward and back arrows cycle through previously-seen pages, the Stop icon stops the loading process, and the Home setting is set (by default) to the NetBeans web site, http://www.netbeans.com/. The Clone Window button to the right of the URL field opens a new browser window.

To run applets in the built-in NetBeans Browser, you must first set the browser as the default applet viewer. In the Explorer, scroll down to the Control Panel section, expand it, right-click on Applets, and choose Properties. For the Viewer choice, choose HotJava. After you compile and execute an Applet, it will then automatically open and run in the built-in browser.

42 Chapter 4. User Interface

4.10. Popup Menus

As you’ve seen other places in this user guide, NetBeans makes popup menus available almost everywhere. These menus, also called “context menus,” give you access to the actions available on the selected object(s). To see a menu, click the right mouse button. The items on a particular menu vary between objects, and even moment-by-moment in some cases; the menus change as the objects change, and objects like threads and processes can change frequently. There are lists of these properties, and more information, in Part IV.

43 III. Working with NetBeans Developer This Part explains how to use the NetBeans IDE to create and run applications. Because NetBeans is written in Java, the approach is always object oriented and frequently different than with other IDEs. Wherever possible, we’ll show you several ways to complete a task so that you can choose the one that fits your personal development style. Specifically, we’ll describe how to use NetBeans’ file system to manage your projects. You’ll see how to generate and edit Java objects and code using the Explorer, Source Editor, Form Editor, templates, and Wizards. Finally, we’ll explain how to debug, compile and execute objects with NetBeans.

44 Chapter 5. Fundamental Operations

5.1. Using Workspaces

While working on any non-trivial project, as you progress through the development cycle (write, edit, compile, debug, execute, edit ...) the screen can be cluttered with windows. While all of these windows are necessary for development, they are generally not all needed simultaneously—you do not need all windows visible all of the time. Consider, for example, the Explorer Window. While you will probably need the Explorer visible initially, as you lay out your packages, and create new objects, you are much less likely to need it during debugging, when you will also need the Debugger view, the Output Window, and the Editor window open. The NetBeans Developer Workspace concept aims to efficiently manage a large number of windows and to group these windows into useful, logical sets. You can flip between workspaces by simply clicking the different Workspace tabs on the Main Window. Any given window can be open on any Workspace—and can be open on more than one Workspace simultaneously. To view the Editor on both the Editing and Running Workspaces, for example, first open the Editor on the Editing Workspace. Double click on a Java data object displayed in the Explorer; the Editor will open with that source. Flip to the Running Workspace by clicking on the Running Workspace Tab on the Main Window. The first Editor window is no longer visible, and you will see either the default set of Running Workspace windows or those you left open when last using this Workspace. Select the Window menu on the Main Window, you will see a list of currently open windows; one of these will be the Editor, and the name of the open source in parentheses. Select this item, and the Editor window will open on the current Workspace—in this case, the Running Workspace. The Editor is now visible on both the Editing and Running Workspaces. It is also possible to open separate instances of some windows which act independently of each other. For example, if you have an Explorer window open on your Editing

45 Chapter 5. Fundamental Operations

Workspace, you can open an entirely separate Explorer on the Debugging workspace by flipping to the Debugging Workspace and clicking the New Explorer icon on the Main Window. This Explorer is a new window; it will not reflect or display changes made to an Explorer on another Workspace. Note that Workspace setup and use is entirely your choice. In fact, you don’t need to use Workspaces at all—your windows may be displayed on a single Workspace, space permitting. However, we believe you’ll find Workspaces valuable for efficient development of your projects. The default Workspace configuration is a standard and logical grouping of most commonly used windows:

• Editing: Explorer, Editor (if any objects are open)

• Running: Execution View, Output Window

• Debugging: Debugger View, Output Window, Editor (if any objects are open) Note that the Main Window is always present on all Workspaces. On exiting NetBeans, the current state of each Workspace is saved. This state information includes open windows, their sizes and positions. When you next launch NetBeans, your Workspaces will appear exactly as you left them. Workspaces are completely customizable: you may add, delete and rename the available Workspaces. See Section 9.4 for further details.

5.2. Exploring Objects

There are four top-level folders under the root Desktop in the Explorer’s data hierarchy. The first, Repository, contains work objects. The second, Templates, contains basic starting points for new development. The last two folders, Control Panel and Environment, hold most of the IDE’s customizable settings.

5.2.1. Repository

The Repository is perhaps the most important segment of the NetBeans Explorer. It holds all files, or “data objects,” that the IDE uses. The repository gives a unified view

46 Chapter 5. Fundamental Operations

of data objects of different types. From the Repository, you can access objects from different sources by mounting different drives, JAR and ZIP archives.

5.2.1.1. Filesystems and the CLASSPATH The concept of filesystems is critical to the architecture of the IDE. A filesystem represents a hierarchy of files and folders. Filesystems can represent plain local files or ZIP or JAR archives. Once mounted, the filesystem transparently hides any differences between these sources. Some default items are added to the Repository when the IDE is launched. User filesystems can be viewed in the Explorer, under Repository—however, there are additional filesystems used by the IDE which are mounted at startup and hidden. All mounted filesystems, including hidden ones, are visible in the Explorer under the Environment | Repository settings.

Once a new filesystem has been mounted, it is equivalent to having added the file or folder to the CLASSPATH accessible by the IDE. The mounted packages and classes are immediately available.

5.2.1.2. The Mount Point An important issue to note when mounting new filesystems is the point at which you mount it. In the same way that the CLASSPATH must contain the correct hierarchy of directories to access the required packages and classes, the point at which you mount those packages and classes is very important. For example, mounting a filesystem from the point C:\work will not give the IDE access to the package project1 stored as c:\work\myprojects\project1. In this case, this filesystem should be mounted at C:\work\myprojects, such that project1 is the top-level package.

5.2.1.3. Mounting New File Systems To mount a new filesystem, right-click on the Repository node in the Explorer and choose Add Directory from the popup menu. Select the directory from the new explorer window and click OK. Add JAR and ZIP archives using Add JAR Archive. To remove mounted directories or JAR/ZIP files from the Repository, right-click on the

47 Chapter 5. Fundamental Operations

item and select Remove From Repository.

5.2.1.4. Working with Packages Objects stored in the Repository are organized in packages which correspond with file folders. All development packages you create when writing an application in NetBeans are stored in the Repository, and you can add, remove, and edit them from the Repository. When starting a new development project, identify the data path / file system (see above) to use for your work, right-click on that path, and select New Package from the popup menu. Once you enter a name for the new package, it will appear in the Explorer under the path you selected. You can create several layers of packages in the same way. Deleting these packages is simple—either choose Delete from the package’s popup menu or press the Delete key on your keyboard. The popup menu commands in the Repository allow a wide range of operations—from creating new packages to changing properties.

Table 5-1. Package Popup Menu Actions

Action Description Explore from Here Opens a new Explorer window with the selected Package as the root. Refresh Folder Updates the view, reflecting any changes to files in the folder made outside the IDE.

Compile Builds and compiles all objects in the selected package, at the selected level in the hierarchy. Compile All Builds and compiles all objects in the selected package and recursively in all subpackages.

48 Chapter 5. Fundamental Operations

Build Builds all objects in the selected package, at the selected level in the hierarchy. Build All Builds all objects in the selected package and recursively in all subpackages. Cut / Copy / Paste / Delete / Rename In addition to the standard keyboard commands, NetBeans enables cutting, copying, pasting, deleting, and renaming from the popup context menu. New Package Creates a new, blank package as a subfolder of the selected package. New from Template Create a new object in this package, using one of the pre-built templates available under the Templates node in the Explorer. Properties Opens a property sheet showing properties of the selected object(s).

5.2.1.5. Working with Objects While working in NetBeans, you operate with data objects rather than plain files. Each data object represents one or more files on the disk. Each data object is presented as a JavaBean—with its own icon and properties. The object types used in the IDE are:

Table 5-2. Object Types

Icon Object Type

Package: A package (folder)—on disk or in a JAR/ZIP archive

Java Object: Represents one Java source file (.java). Its children represent methods, variables, constructors, and inner classes acquired by parsing the Java source.

49 Chapter 5. Fundamental Operations

Form Object: represents one Java source file which can be edited visually in the NetBeans Form Editor. The two types of children are: First, classes with methods, variables, constructors, and inner classes acquired from parsing Java source; second, items representing components on the form (visual hierarchy).

Class Object: represents one Java class without source code. Children are methods, variables, and constructors acquired from Java introspection.

JavaBeans: classes (without source code) which are JavaBeans—that is, they have the default constructor and are serializable. Two advanced operations can be done with JavaBeans. First, you can customize JavaBeans (using the Customize Java Bean action) and make serialized prototypes from the customized object. Second, you can copy and paste JavaBeans directly into the Form Editor (without the need to install them to the Component Palette first).

Serialized Prototypes: files with a “.ser” extension, which are serialized JavaBean objects. You can do two things with these objects: First, customize the serialized object (using the Customize Java Bean action) and make a new serialized prototype from it. Second, copy and paste the serialized JavaBeans directly into the Form Editor (without the need to install them to the Component Palette).

HTML Object: represents an HTML file. (The filename extensions for HTML files can be set in Control Panel | Extensions.)

Text Object: represents a text file. (The filename extension for text files can be set in Control Panel | Extensions.)

50 Chapter 5. Fundamental Operations

Image Object: represents GIF or JPEG images. You can view these with the built-in image viewer.

There are two basic ways to create new objects. First, you can use the New command in the Main Window toolbar or menu. The second possibility is to right-click on the package where you would like to place the new object and select from the templates on the popup menu (see instructions on how to use Templates, below). Objects can be removed using the delete button in the Explorer toolbar or by pressing the Delete key. See Section 5.3 for more information about creating new objects. For each object type, you can access its popup menu, which will include:

Table 5-3. Common Object Actions

Action Description Open Opens the default viewer for the object type. For example, for a Java object, the Editor will open; for an HTML object, a browser window will open. Compile Compiles selected object(s) Execute Runs the selected object Cut / Copy / Paste / Delete / Rename Standard clipboard-style operations Save as Template Publishes the selected object as a template for future use Properties Opens a property sheet showing properties of selected object(s)

5.2.2. Templates

The second major grouping in the Explorer hierarchy is Templates. Here you will find

51 Chapter 5. Fundamental Operations

the standard set of templates, in several categories: Classes, AWT Forms, Swing Forms, Dialogs and Other. Each category contains several templates for creating new objects. The predefined categories can be managed in the same way as packages in the Repository—you can create a new category, rename it, or remove an existing one. For more information, see Section 5.4.

5.2.3. Control Panel

The Control Panel segment of the Explorer provides access to the IDE system settings, including internal compiler configuration, Debugger settings, window settings, external browser or applet viewer configuration, and more. By clicking on the Show Property Sheet icon on the Explorer’s toolbar, you can see the various options for each item on the Control Panel. For more information, see Chapter 8.

5.2.4. Environment

Settings in the Environment section of the NetBeans Explorer provide access to the objects that represent various parts of the IDE at runtime. These include Repository settings, Main Window settings such as menus and toolbars, workspaces, all available actions and more. Environment also displays various runtime information for execution (executed processes) and the Debugger (breakpoints, watches, ...). Chapter 9 has details of all customizations described below.

5.2.4.1. Repository Settings

Repository settings list all mounted filesystems. You can customize the appearance and behavior of file systems that are currently mounted—local directories and JAR/ZIP archives. If a new filesystem is added in the Repository, it will automatically appear as one of the items in the Environment tree. You can also use the context menu on the Repository Settings to add new filesystems.

52 Chapter 5. Fundamental Operations

5.2.4.2. Main Window Under the Main Window, you will find various customization settings for the Menu, the Toolbar, and all of their elements. For the Main Window itself, you can set the default location and size in pixels. Under the Menu node, you will find settings for each item on the Main Window menu, including File, Edit, Build, Debug, Tools, Window, and Help (and their submenus!). You can add, remove, and customize commands for each menu item. For example, by cutting and pasting, you can change the order of the menu items, enable or disable them, and insert separators.

5.2.4.3. Workspaces By changing properties of items in the Workspaces category, you can add, remove or rename “virtual desktops” and copy or move the windows among them. For example, it might be helpful to have the Web Browser running during editing. You can also set the appearance of each workspace, including fonts, colors, and titles.

5.2.4.4. Shortcuts The NetBeans IDE is built to be customized, and one of the easiest ways is to set your own shortcuts for often-used operations. Shortcuts are simple keyboard commands that let you skip tedious mouse actions. In the NetBeans Explorer, expand the Environment node, and expand Shortcuts. There, you will see a list of the default actions and, in the Property Sheet for each, their default keyboard settings. You can open a new object, for example, by either clicking with the mouse on File | New or by pressing Ctrl+n on the keyboard. To change the setting for an action, go to the Property Sheet, select the Shortcut input field, and perform the set of keystrokes you would like to use as the new shortcut (that is, hit the control key itself and a letter key to register the shortcut). If you set a duplicate shortcut, NetBeans will alert you by displaying an Exception message. It will then revert to the original setting.

5.2.4.5. Component Palette

53 Chapter 5. Fundamental Operations

In the Component Palette section of the Explorer, you can add, remove, move, change the order of, or edit components. From a component’s popup menu, you can move it up or down, cut, copy, delete, or set Properties (the same properties sheet as you can access from the Explorer using the Show Property Sheet toggle button).

5.2.4.6. Debugger During a debugging session, the Debugger shows individual watches, threads and breakpoints. By right-clicking on Breakpoints or Watches, you can also add a new breakpoint or watch. There’s a detailed description of the Debugger in Section 6.5.

5.2.4.7. Processes The Processes node lists all processes currently being executed within the IDE. The popup menu for each of these items contains just one element: Terminate Process. This allows you to force termination of a process. This view is mirrored by the Execution window.

5.2.4.8. Actions Under Actions in the Explorer hierarchy, you can see all available actions in the IDE. They can be copied to the Main Menu, Toolbar, or Shortcuts using standard clipboard operations (copy, paste).

5.3. Creating New Objects

There are several ways to create new objects: 1. Choose the New action either on the toolbar or from the File | New menu. A window will appear for selecting the template from which you will create the new object. You can either double click on the template’s icon or select the icon and click OK. In the dialog that appears, enter the name of the new object and select the folder/package where the object should be created.

54 Chapter 5. Fundamental Operations

2. In the Explorer’s Repository, select the package in which you want to create the new object, open its popup menu, and select a template under New from Template>. In the dialog that appears, enter the name of the new object. 3. Double click on any template under Templates in the Explorer, or anywhere under the Repository. (Note that you can set any object to be a template. For details, see Section 5.4.) In the dialog that appears, enter the name of the new object and select the folder/package in which the object should be created. After the new object is created, a default editor on this object will be opened if the object supports editing. (For example, no editor is available for Class objects.)

5.4. Using Templates

In the NetBeans IDE, any data object can be used as a template. There are two ways to set an object as a template: 1. Select the desired object in the Repository (under Explorer) and select Save as Template from the popup menu. A dialog will appear for you to choose the template category where the object should be copied. 2. Select the desired object in the Repository and change its isTemplate property to “true” in the property sheet. You can also copy this object to a template category under the Templates node; this will make the object visible in the window that appears when the New action is chosen on the menu or toolbar. The difference between a template and a normal object is only in what is done when you double-click on it in the Explorer. For plain object, a default editor is opened (if available); on templates, a dialog will appear that allows you to create a new object from the template. You can still open an editor on templates by choosing Edit from the template’s popup menu.

55 Chapter 6. Developing Java Classes

6.1. Exploring Java Objects

Java Objects represent source files on a filesystem. Each Java source file contains at least one class within the source and contains code representing methods, constructors and variables. as documents in the Explorer. Subtrees of each Java data object represent the hierarchy of classes and inner classes.

Table 6-1. Document icons of Java Objects

Icon Description

Java Object

Class Object: represents one Java class without source code.

Runnable Java Object

Incorrect Java Object (in a bad package or cannot be parsed)

JavaBean (public, not abstract class which has public default constructor)

Runnable Java Bean

Form Object

Runnable Form Object

Incorrect Form Object (in a bad package or cannot be parsed)

6.1.1. Elements of Java Objects

Subtrees of each Java object represent the hierarchy of elements. For each element, you

56 Chapter 6. Developing Java Classes

can set appearance and behavior properties. For example, each Java object contains at least one class; the class contains constructors, methods, variables and inner classes.

Table 6-2. Java Object Elements

Icon Elements Properties

Class, Inner class Name, modifiers, extended class, implemented interfaces

Interface, Inner interface Name, modifiers, extended interfaces

Form Represents visual form hierarchy

Constructor Name, modifiers, arguments, exceptions

Method like constructor, plus Return type

Variable Name, modifiers, type, initial value

Initializer Static

Elements listed above can have several kinds of accessibility. The icons of the elements consist of icons in previous table and the accessibility flag(s).

Icon Access

private

package private

protected

public

6.1.2. Creating New Elements

Select the class (interface) in which you want to create a new element. Then use the

57 Chapter 6. Developing Java Classes

popup menu and select Create. In the expanded submenu, choose the element you want to create.

6.2. Editing Java Objects

6.2.1. Layout of the Java Editor

The top of the Editor Window has one or more tabs used to view different documents. From each of these tabs, the document can be saved, docked/undocked, or closed. For more detail, see Section 4.4.1 and Section 4.4.1.2.

6.2.2. Layout of the Java Editor

The Java Editor contains source code that is syntactically colored. Different colors are associated with different text properties. For example, in default mode, all keywords are shown in blue and all comments in light gray. “Guarded text” generated by the form editor has a blue background and cannot be edited. In the bottom left corner of the Editor Window is the Status Bar. This bar indicates the cursor position and the insertion mode. Cursor position is given in the form of Row-number:Column-number. Insertion mode is either INS (Insert) or OVR (Overwrite) and can be toggled between these modes using the Insert key on your keyboard. There are many built-in keyboard shortcuts for navigation and editing, as well as abbreviations for commonly used keywords.

6.2.3. Integration with Other Components

The editor is integrated with other parts of the IDE. More detail may be found in each section, however, a synopsis is provided below:

• Form Editor: All actions are reflected in the source editor.

• Explorer: Changes in properties and creation of new classes, methods, and

58 Chapter 6. Developing Java Classes

variables, etc. are reflected in the source Editor. There are three ways to open a file in the Editor: press Return, select Open from the right-click popup menu, or double-click on a node representing a class, method, variable, etc.

• Debugger: When a program stops during execution, the editor automatically jumps to the breakpoint where the code was interrupted. Toggle breakpoints with Ctrl+F8.

• Compiler: Begin the compilation process by pressing F9; this will compile the active source (the file whose tab is “in front” of the Editor). If there’s a bug, it will be highlighted in red in the Output Window; press Return or double-click on that line to jump to the buggy code in the Editor. The Source Editor has default font size, style, and color settings. You may customize the properties for Java, HTML, and text under the ControlPanel subentries JavaEditor, HTMLEditor, and TextEditor, respectively. Section 8.15 lists these properties.

6.3. Compiling Java Objects

6.3.1. Compiling Single Classes There are several ways to compile Java sources in the IDE. A Java Object can be compiled from the Explorer by opening its popup menu and choosing Compile. A Compile button is available on the Main Window; you can also use the keyboard shortcut F9. Each of these methods require that you first select the Java Object you wish to compile, either by selecting it in the Explorer or by giving focus to the Editor window with the source text.

6.3.2. Compiling Packages Selecting Compile when a folder is selected will compile all sources in that folder which have been modified since they were last compiled, or if they have not been previously compiled. Compile All will do this recursively on a folder and all its sub-folders.

59 Chapter 6. Developing Java Classes

Build is slightly different in that it forces re-compilation of all sources in a folder, whether they are current or not. Build All recursively Builds a folder and all sub-folders. Build is accessible from the popup menu of a folder in the Explorer and via the Build icon on the Main Window.

6.3.3. Shortcuts

There are two predefined shortcuts for compilation actions. The first, already mentioned, is F9; it compiles the selected Java Object(s) or folder. The second is Alt+F9 which builds the selected Java Object(s) or folder.

Section 9.2 explains how to customize shortcuts. For a list of all shortcuts, see Appendix A.

6.4. Executing Java Objects

Java Objects, or more exactly applications that are represented by Java Objects, may be executed in several ways. First, the Java Object must be selected and must be executable. A Java Object is executable if it either has a main() method or is a subclass of an Applet class. If so, it may be executed by right-clicking on it in the Explorer and selecting Execute from the popup menu. Alternatively, select the Execute button on the Main Window or use the Keyboard Shortcut Ctrl+F9.

Normally, these actions first compile the selected Java Object. Assuming compilation completes successfully, NetBeans then switches to the Running Workspace, though this is configurable via Control Panel | Internal Execution/properties | Workspace, where the application is executed. Such a process has constraints: it can not create its own SecurityManager, URLStreamHandlerFactory, etc. On the other hand, it allows you to write and execute programs that affect Developer’s behavior (see the Examples directory in the Development directory). To switch between external (heavy weight process) execution and internal (ThreadGroup) go to Control Panel | Java Object | Properties and toggle the External Execution Enabled property.

60 Chapter 6. Developing Java Classes

6.4.1. Running Applets, Specifying Applet Viewer

Applets are executed the same way as any other Java Object. See the section Executing Java Objects, above. You can specify the properties of the applet viewer by double-clicking on the Applet node in the Control Panel. The Developer IDE provides three options to view applets: through an External Viewer such as Netscape Navigator or Microsoft Internet Explorer, the internal Web Browser (HotJava), or Sun’s JDK utility AppletViewer. The default setting is an AppletViewer used as the external viewer executed within the same VM as the IDE. To choose the type of viewer, either double-click on the word “Viewer” repeatedly to rotate through the menu or use the pull-down menu. To use the external viewer, you must select this option and provide the name and location of your viewer. Click once on the text next to the words “External Viewer” and either type in the information manually (example: C:\Program Files\Netscape Communicator\Program\netscape.exe) or double-click on the “...” icon to browse for the file.

6.4.2. Running Applications

You can run Java applications using either internal or external execution. Both have their advantages and disadvantages:

• External Execution (default setting): A new VM is invoked for executing the application. This enables you to run applications which require special VM, JDK 1.2 support, or need to do operations that aren’t possible with internal execution (see below). You can specify the VM executable (such as java.exe) and complete command line parameters together with CLASSPATH settings for the application. (See Section 5.2.1.1 for details about the CLASSPATH and Section 8.8 about setting the executor’s parameters.)

• Internal Execution: An application run using internal execution runs inside the same virtual machine (VM) as the IDE itself. This brings the advantage that the application can modify the IDE itself. But it imposes two restrictions on the executed application. The application cannot install its own URLStreamHandlerFactory and SecurityManager (so you will not be able to run, for example, RMI applications).

61 Chapter 6. Developing Java Classes

Also, if the executed application crashes, the IDE crashes with it. You can pass command-line arguments to executed Java applications. Select the Java Object in the Explorer and use Build | Set Arguments from the main menu to set its command-line arguments. Alternatively, you can select the object in the Explorer and edit its Arguments property (which can be found under the “Execution” tab on the object’s property list). Note for Advanced Users: Some applications, such as Abbrevs.java in the provided examples may require the use of internal execution because they’re intended to modify the IDE itself. You can use the flag “Use Internal Execution” on the Java Object’s property list (on the Execution tab) to enforce the use of internal execution without the need to switch the global setting.

6.5. Debugging Java Objects

The Debugger can be used to present “snapshots” of the system state during execution. By placing breakpoints at key positions throughout your source code, the Debugger can halt at these points and display details of the current environment at that point in the source. You can effectively step through your code, monitoring execution as it occurs. The Debugger Window is a three-tabbed display with tabs for Breakpoints, Threads, and Watches.

6.5.1. Breakpoints

The Breakpoints tab simply lists the currently set breakpoints, showing the class name, and the line number on which the breakpoint has been set. To add a new breakpoint to your code, position the cursor at the desired line in the Editor window and select Debug | Toggle Breakpoint from the Main Window. Alternatively, use the keyboard shortcut Ctrl+F8. The current line will be highlighted blue to indicate the breakpoint has been set. To remove a breakpoint, first position the cursor on the line where the breakpoint has been set, and repeat the procedure above: either use the Main Window Debug menu, or press Ctrl+F8. Breakpoints can also be removed directly from the Debugger window by right clicking on a listed breakpoint and selecting Delete from the popup

62 Chapter 6. Developing Java Classes

menu.

6.5.2. Threads

The Threads tab displays all threads in the current debugging process. These threads are an expandable hierarchy; each thread containing CallStack and Locales nodes. The CallStack node can be expanded to show the history of calls made during execution; the Locales node displays local variables and their current values in the context of the current thread. If the process you are debugging has more than one thread, all threads appear in the Threads tab showing a thread name and current status (such as “running,” “at breakpoint,” and “suspended”). Only stopped threads display “current” system information.

6.5.3. Watches

The Watches tab lists all currently set watches or values of local variables. By watching a variable, you can monitor its value at various stages during execution. To watch a variable, either select the Add Watch item from the Debug menu on the Main Window or select Add Watch from the popup menu of the root “watches” item on the Watches tab of the Debugger Window. A dialog box requesting the name of the variable to watch will open. Once you have entered the name of a variable in your source and clicked OK, it will be listed in the Watches tree. Click on this item in the list to select it and display its property sheet, which displays the current value of that variable.

6.5.4. The Debugging Session

Use the Debug | Go menu item from the Main Window to initiate a debugging session, or press F5. NetBeans Developer will switch to the Debugging Workspace (though this is configurable, as described in Section 9.4); it will open the Debugger Window, the Editor with the source being debugged, and the Output Window. The Output window is split vertically, with debugger output on the right and any output from the application being debugged on the left. When the Debugger reaches a breakpoint in your source, that breakpoint will be highlighted pink. Once execution has halted at a breakpoint, use the Trace Into and Trace Over menu

63 Chapter 6. Developing Java Classes

items under the Main Window Debug menu (F7 and F8, respectively) to proceed. Trace Into steps into the method at which the debugger is currently stopped and again breaks, allowing you to observe execution incrementally. Step Over executes the current method without breaking and stops at the next statement. By repeatedly stepping through your code like this, you can monitor whatever parts of the system you choose during execution of the code.

6.6. Designing Visual Forms

6.6.1. Creating a New Form, Opening Form Editor Use the “New” action to create a new form from a template and open the Form Editor on it. NetBeans supports nine basic form types from both the Java Abstract Windowing Toolkit (AWT) and the newer Swing API. The table below lists them.

Table 6-3. Basic Form Types Supported by NetBeans

Name Description Frame AWT Frame (top-level application window). Dialog AWT Dialog (window for user feedback). Applet AWT Applet (embeddable program run by a Web browser or other applet viewer). Panel AWT Panel (container for holding parts of an interface—can be then used in another Frame or Panel). JFrame Swing JFrame (top-level application window). JDialog Swing JDialog (window for user feedback).

64 Chapter 6. Developing Java Classes

JApplet Swing JApplet (embeddable program run by a Web browser or other applet viewer). JPanel Swing JPanel (lightweight container for holding parts of an interface—within a JFrame or another JPanel). JInternalFrame Swing JInternalFrame (lightweight object with many of the features of a native Frame, used as a “window within a window” within a JDesktopPane).

Note that the table lists only the basic types—which differ in the look during design time and in the code generated for the form’s class. Any customized form (for example, a Dialog with OK and Cancel buttons) can be saved as a new template. To open a Form Editor for existing forms, double-click on the form object in the Repository or use “Open” from its popup menu. When a form is opened, three windows are displayed: 1. Form Window: The design-time view of the form. 2. Editor Window: Contains the Java source for the form. If the Editor was already open, the form is opened on a new tab within that Editor window. 3. Component Inspector: Displays the hierarchy of components on the active form; the current selection of components is highlighted. Tabs on the property sheet display the properties, layout and events of the selected component.

6.6.2. Form Editor Basics

This section explains the basic operation of the Form Editor. The Form Editor and Component Palette (on the Main Window) work together. The Component Palette has three modes: Add Mode, Selection Mode, and Connection Mode. These modes are described in the sections below. The last section explains how to reorder the components displayed in the Form window.

65 Chapter 6. Developing Java Classes

6.6.2.1. Adding New Components

The Component Palette’s Add Mode adds components to the form.

Figure 6-1. Component Palette Indicating Add Mode

You can add a new component to a form in two ways: 1. Choose a component in the Palette by clicking on its icon; this sets Add mode. Next, click on the Form Window to add the component of the type you chose. (The mode then automatically changes to Selection mode—unless you hold down the Shift key to add multiple components of the same type.)

Depending on the layout used, you can add a component to a specific position (Border and Absolute layouts), and/or set the default size of the component by dragging the mouse (AbsoluteLayout).

2. In a Repository, find the class of the JavaBean you want to add and click on it. Then use the popup menus to Copy it to the clipboard and Paste it to the place in the Form Window where you want to add it.

When adding components to the Form Window, hold the Shift key to add multiple components of the same type.

6.6.2.2. Selecting Components

You can select components in the Form Window either from Selection mode (the default mode, shown in the Figure below) or by selecting component nodes in the Component Inspector’s tree.

66 Chapter 6. Developing Java Classes

Figure 6-2. Selection Mode

To select multiple components when clicking on the Form Window, hold down the Ctrl key. The Component Inspector displays the current selection on the active Form Window. Its property sheet displays the properties of the selected component—or, if more than one component is selected, their common properties are displayed. To select a component in the Component Inspector’s tree, click once on it. To select multiple components, hold down the Ctrl key and click each one. You can also select a group of components by clicking on the first one, then holding the Shift key and clicking on the last component in the group.

6.6.2.3. Connection Mode In Connection Mode, you can click on two components on the form (or in the Component Inspector) to start the Connection Wizard.

Figure 6-3. Connection Mode

Section 6.6.7 explains the Connection Wizard.

6.6.2.4. Copying Components To copy or move components, first select the item(s). Use Cut or Copy on the popup menu. Then select the destination and select Paste on its popup menu.

67 Chapter 6. Developing Java Classes

The components will be copied with all properties and events—although events are maintained only if copying within the same form.

6.6.2.5. Reordering Components A container is a Java visual component that can contain other components. For example, a Panel is a container. The order of components within their parent container determines the order in which they appear. For some layouts (such as FlowLayout), modifying the order is the only way to modify the layout. There are two ways to change the order:

• Select the component you want to move, and use the Move Up / Move Down items in its popup menu.

• Select the parent container and choose “Change Order” from its popup menu. You’ll get a popup menu for setting the order of all subcomponents in the container.

6.6.3. Working with Layouts LayoutManager is a special Java class which manages the positions and sizes of components in some container. (Examples of containers are the AWT Dialog, Frame, and Panel, as well as the Swing JPanel, JDialog and JFrame components.) NetBeans’ Form Editor has advanced support for Layout managers. In addition to absolute positioning, complex forms based on Flow, Border, Card, Grid, GridBag or Swing’s BoxLayout are supported. (These layout managers are described in Section 6.6.3.2.)

6.6.3.1. Setting and Changing Layout Managers Various containers come with different predefined layout managers:

• Frame, JFrame, Dialog, JDialog, JInternalFrame have the BorderLayout by default;

• Panel, JPanel have FlowLayout as the default layout. Some containers—ScrollPane, JScrollPane, JTabbedPane, JLayeredPane/JDesktopPane, and JSplitPane—do not provide the ability to change

68 Chapter 6. Developing Java Classes

layout managers. These are containers which rely on a specific layout manager.

You can change the LayoutManager in two ways:

• Select the desired LayoutManager in the Component Palette (by default, under the Layouts tab). Then, on the form, click inside the container whose layout you want to change.

• Right-click on the target container—either on the form or in the Component Inspector—and change the Layout using the “Set Layout >” submenu.

If you change a layout, the constraints that were used on the previous layout are remembered. Therefore, if you change the layout back to the previous one, the layout looks the same as it did previously. (Note: The only exception to this happens if you’re using an AbsoluteLayout and you change to a GridBagLayout. When you change from Absolute to GridBag, the GridBag constraints are created so that the GridBag layout looks the same as the previous AbsoluteLayout.)

6.6.3.2. NetBeans’ Support for LayoutManagers

The NetBeans Form Editor support for LayoutManagers comprises:

1. Design mode of layout managers.

69 Chapter 6. Developing Java Classes

Figure 6-4. Layout Form

The layout manager in design mode can support:

• Drag’n’drop of components. Select a component and click in the exact location you want it added. This is currently supported for AbsoluteLayout and BorderLayout managers.

• Auto-adaptive layout at design time. NetBeans approximates the run-time behavior of the chosen layout manager as much as possible—but behaves differently, as needed, to allow component placement.

2. Layout Properties. Use these properties to modify the layout manager’s global settings—such as the vgap/hgap properties of BorderLayout (see the property sheet shown) or the alignment property of FlowLayout. The layout manager for a container is always the first child in its Component Inspector tree; see the example here. To set the layout properties, select the layout’s node; the layout properties will be displayed in the property sheet.

70 Chapter 6. Developing Java Classes

Figure 6-5. Layout Properties

3. Constraints Properties. These are the properties specific for one component that is managed by the Layout Manager—e.g. the Direction property when BorderLayout is used—it is different for different components under BorderLayout (the values can be North, South, West, East or Center). To view or set these properties, select the component and choose the Layout tab in the Component Inspector.

71 Chapter 6. Developing Java Classes

Figure 6-6. Constraints Properties

4. Other features include creating GridBagLayout based on previously used absolute positions. You can simply create the form in AbsoluteLayout, then change the layout to GridBagLayout; the GridBagConstraints of these components will be created so that the layout looks the same as when the absolute positions were used.

6.6.3.3. Layout Managers Summary

6.6.3.3.1. AbsoluteLayout AbsoluteLayout is a LayoutManager which lets you put a component in a fixed location which won’t change as the environment changes. It is a substitute for “null” layout and provides a cleaner implementation of placing components on absolute positions.

This layout manager is implemented in com.netbeans.developer.awt.AbsoluteLayout and com.netbeans.developer.awt.AbsoluteConstraints. These two classes must be

72 Chapter 6. Developing Java Classes

distributed with the final application that makes use of the AbsoluteLayout—they are ready for deployment in the file AbsoluteLayout.zip (in the %NETBEANS_HOME%/redist directory). You can freely redistribute this archive with applications developed with the NetBeans IDE.

6.6.3.3.2. BorderLayout A BorderLayout arranges components in a container at five positions: in the center and along four edges “north” (top), “west” (left), “south” (bottom) and “east” (right edge). The horizontal and vertical gap properties control spacing between the components.

6.6.3.3.3. FlowLayout A FlowLayout arranges components in a container like words on a page: it fills the top line from left to right, then does the same with lines below. You can specify the alignment of the rows (left, center, right). You can also set the horizontal spacing between components and the vertical spacing between rows.

6.6.3.3.4. GridLayout The GridLayout divides its Container into a configurable number of rows and columns. Like the FlowLayout, components are added to the grid from left to right and top to bottom. But unlike FlowLayout, the dimensions of the grid are fixed; individual components aren’t allowed to have different sizes.

6.6.3.3.5. CardLayout Think of a CardLayout as a deck of cards. Only one component (“the top card”) is visible at a time and each component (“card”) is the same size. In the Properties sheet, you can set the Current Card property to card1, card2, etc. In code, the methods show(cardid), next(), previous(), first(), and last() can be used to select cards. For example, the following code selects the next card in panel1 when button1 is clicked: private void but- ton1ActionPerformed(java.awt.event.ActionEvent evt) { // Add your handling code here: CardLayout cards = (CardLayout)panel1.getLayout(); cards.next(panel1); }

73 Chapter 6. Developing Java Classes

Also see the JTabbedPane component. It implements a similar layout with a labeled tab for each component.

6.6.3.3.6. GridBagLayout A GridBagLayout lets you set almost any layout you want. (A GridBagLayout shouldn’t be confused with a GridLayout.) A GridBagLayout uses a fairly complex set of constraints that’s not simple to learn. Luckily, with NetBeans, you don’t need to understand! Just use AbsoluteLayout, place the components, and change the layout to GridBag. The constraints code will be generated for you. In some situations, a GridBagLayout may be preferable to an AbsoluteLayout. That’s because the GridBag constraints can adjust to a new environment, keeping the same layout as the container changes. An AbsoluteLayout, on the other hand, stays static and may look poor. That’s especially true when using native components, such as AWT components, that have different sizes on different platforms: an AbsoluteLayout that looks perfect on one platform could look terrible when the code runs on another platform. The GridBag constraints can take care of problems like that. (And, as noted above, NetBeans can generate GridBag constraints automatically from your AbsoluteLayout.)

6.6.3.3.7. BoxLayout The BoxLayout is part of the Swing API. It lets multiple components be arranged either vertically (along the Y axis) or horizontally (on the X axis). Components won’t wrap—even when the container is resized. Components are arranged from left to right or top to bottom in the order they were added to the container. (Of course, you can change the order as explained earlier.)

6.6.3.4. Support for Custom Layout Managers NetBeans has support for using custom layout managers in the FormEditor. If your LayoutManager has a default constructor and does not use constraints for adding components, you can use this LayoutManager in the Form Editor during design-time. Simply install the LayoutManager in the Component Palette and you can start using it

74 Chapter 6. Developing Java Classes

in the Form Editor. To do that, go to the Explorer and copy the LayoutManager’s class from the Repository to some palette category under Environment | Component Palette. (You have to add the directory or JAR archive containing the LayoutManager’s source or class to the Repository.) The API for adding support for more complex layout managers will be published later.

6.6.4. Working with Source Code The Editor window displays the current code for a currently opened form. Some source code can’t be edited because it’s generated automatically. You also may use an external editor program with some restrictions.

6.6.4.1. Non-editable Blocks Some parts of the source code are generated by the form editor. These parts aren’t editable:

• the block of variable declarations for the components on the form;

• the method initComponents(), in which all the form initialization is performed. (This method is called from the form’s constructor.);

• header (and trailing closing bracket) of all event handlers.

If you want to perform some additional initializations of a form’s components, you can do it in the constructor after the call to the initComponents () method. Here you can, for example, initialize a ButtonGroup or set component labels from Resource Bundles.

6.6.4.2. External Modifications Forms are stored in two files:

• a .java file, which contains the (partly) generated Java source;

• a .form file, which stores the properties and layout constraints of JavaBean components on the form;

75 Chapter 6. Developing Java Classes

You can edit the .java files using external editors (not simultaneously when the form is edited in NetBeans), with the following exceptions:

• Do not modify the content of the initComponents () method. The body of this method is always regenerated when the form is opened.

• Do not remove or modify any of the special comments places in the source by NetBeans’ Form Editor ( // GEN-...). (These comments are not visible inside NetBeans’ source editor.)

• Do not modify the block of variable declarations. These are always regenerated when the form is opened.

6.6.5. Form Editor Modes The Form Editor can be in one of three modes:

Table 6-4. Form Editor Modes

Toolbar Description

Design Mode. This is the default. By clicking on the form you can select, add, or drag components. Note that, in this mode, depending on the layout, a layout won’t necessarily look the same as it will during run-time. This is because design would be difficult if every layout manager worked exactly the same way at design time as it does during run time. For example, with some layout managers, when you drop two components next to each other, they could resize automatically and make it impossible to add a new component between the two. So, if you need to see the effect of a certain layout manager at run time, change the Form Editor from Design Mode to either Real Mode or Test Mode.

Real Mode. Layouts look the way they will during run-time. You can select or add components, but dragging components is disabled.

76 Chapter 6. Developing Java Classes

Test Mode. In this mode, the form behaves exactly the same as during run-time—when clicking on the form, the mouse events are delivered to the real components. Thus, for example, a button is pressed when you click on it. This mode is suitable for checking the look&feel of the form without the need to compile and run it.

To switch between Design and Real mode, use the Design Mode action (the square with a hash pattern inside) from the toolbar. If the action is “depressed” (a lighter color—as shown in the Design Mode example above), you’re in Design Mode. Otherwise, you’re in Real Mode. Switching to Test Mode is done using the Test Mode action on the toolbar; this is a toggle action, which means you click to enable it and click again to disable. Note that switching Test Mode on disables the Design Mode button; to enable it again, Test Mode must be switched off. These modes are kept separately for each form.

When switching Test Mode on, the form is resized to its preferred size—this is how it will look if it will not be explicitly resized by calling setSize() or setBounds().

6.6.6. Events

Events are managed through the Events tab in the Component Inspector, which gives a list that matches each event sent by an Object with its corresponding handler method. There’s also an Events entry on an object’s popup menu in both the Component Inspector and Explorer. A new component won’t have event handlers defined; the values will all be . From the Component Inspector Events tab, there are two ways to choose a new name and generate the listener and handler code. One is to simply click on the value and a default name will be chosen. After that, you may type over the default name if you want to use a different one. In both cases, remember to press the Return key to generate the code for the listener and body of the handler method; if you don’t, your changes will be ignored. A third way to generate the code is from the Events entry on

77 Chapter 6. Developing Java Classes

an object’s popup menu.

If multiple events are of the same type (for example, both FocusGained and FocusLost are both of type java.awt.event.FocusEvent), then you may use the same handler for all of them. Do that by setting the handler name for the first one as described above—for example, set FocusGained to use the button1FocusChange handler. Then enter the same handler name for the others—for instance, set FocusLost to also use button1FocusChange.

If you enter a new name for an existing handler, the code block will automatically be edited to use the same name. If you delete a name, the code block will be deleted. If more than one uses the same name (and the same block of code), deleting a single reference to the code will not delete the code; only deleting all names will delete the corresponding code block, and a warning dialog will be displayed first.

6.6.7. Using the Connection Wizard

The Connection Wizard allows you to add functionality to the form without having to write any code by hand.

To start the Connection Wizard, first switch to the Connection mode on the Component Palette (as described above). Next, click on two components. The connection source is some event of the first clicked component and the target is the component that was clicked second. You can click on the Form—or click in the Component Inspector (which allows you to also use non-visual components as parts of the connection). In either case, the Connection Wizard will open to connect the selected components.

The Connection Wizard will allow you to set the connection parameters in two or three steps:

1. Connection Source

The first step allows you to select the Source component’s event on which the action should be performed and the name of event handler method which will be generated (the same way as if you add a new event handler via the property sheet).

78 Chapter 6. Developing Java Classes

Figure 6-7. Connection Wizard - Step 1

If you select an event which already has an event handler attached (the name of the event handler is visible in the tree of events after the event name—like “ActionPerformed [button1ActionPerformed]”)—when clicking Next, you will be asked if you want to delete the old event handler. If you answer yes, the old event handler will be replaced with the connection code

79 Chapter 6. Developing Java Classes

when the Connection Wizard is finished.

2. Connection Target The second step allows you to specify the action which should be performed on the target component. There are 3 possibilities, which can be changed using the radio buttons along the top of the dialog:

• Set Property: allows you to set a property on the target component. In the next step you will specify the property value.

• Method Call: allows you to call a method on the target component. In the next step you will specify the parameters for the method call.

• User Code: allows you to write the code by hand. When you select this option, the “Next>” button will change to “Finish” so as there are no settings left. Note that selecting this is equal to creating the event handler from the property sheet—i.e. an empty event handler method is generated, and the cursor in editor is placed into the new event handler allowing you to write the handling code by hand. 3. Selecting Property Value or Method Parameters If you selected “Set Property” or “Method Call” in the previous step, the third step will allow you to specify the values for the target property or parameters for calling the target method. If you selected the “Method Call,” the dialog will display a list of all parameters types as tabs, where each tab represents a single method parameter. On each tab, you can set the source from which the value (of specified type) is acquired:

• Value: This option is available only if the value is of primitive type (int, float, ...) or String. You can enter the value into the text field.

• Property: This option will allow you to acquire the value from a property of some component on the form. If you click on the “...” button, a dialog will appear which will let you select the component and its property. Note that only properties of the right type are listed.

80 Chapter 6. Developing Java Classes

• Method: This option will allow you to acquire the value from a method call of some component on the form. If you click on the “...” button, a dialog will appear which will let you select the component and its method. Note that only methods which return the right type, and methods which do not take any parameters are listed.

• User Code: This option will allow you to write user code, which will be used as the parameter for the setter of the selected property or a parameter of the selected method call. If you click Finish, a new event handler will be generated with a code reflecting the settings entered in the second and third step.

6.6.8. Menu Editor

The Form Editor can create and modify menus. The AWT and Swing variations of both MenuBar and PopupMenu are supported.

6.6.8.1. Creating a Menu Bar To create a new Menu Bar, click on the AWT or Swing MenuBar component in the Component Palette, as shown below. Then click anywhere on a form to which you want to add the menu. The menu will appear under the Non-visual Components list in the Component Inspector.

Figure 6-8. Creating MenuBar

If this is the first menu bar you have added to this form, it will also appear visually on the form. Please note that, for AWT forms, only AWT’s MenuBar can be used as the

81 Chapter 6. Developing Java Classes

main menu. The same is true for Swing forms and the JMenuBar. It is possible to add AWT’s MenuBar to Swing forms and vice-versa, but you will not be able to use it as the main menu for this form.

You can add multiple menu bars to one form, but only one of these can be used as the current menu bar. To change the current menu, select the form in the Component Inspector and edit its “Menu Bar” property:

Figure 6-9. Menu

82 Chapter 6. Developing Java Classes

6.6.8.2. Creating a Popup Menu

To add a popup menu to a form, first click on the AWT or Swing PopupMenu component in the Component Palette; then click anywhere on the form. The new menu will appear under the Non-visual Components list in the Component Inspector. You can use the same editing features as with MenuBar. To visually use the popup menu, write code like this:

popupMenu1.show (component, 100, 100);

where you want to show the popup menu. The API documentation for PopupMenu and JPopupMenu has more details about displaying popup menus.

6.6.8.3. Adding Menu Items

To add new menu items, submenus or separators, use the Component Inspector. The MenuBar’s node in the Non-visual Components contains subnodes which represent the hierarchy of the menu. To add new items, right-click on the menu node and use a New action, as shown below:

83 Chapter 6. Developing Java Classes

Figure 6-10. Adding Menu Items

6.6.8.4. Menu Item Events

84 Chapter 6. Developing Java Classes

You can use the same mechanism for assigning event handlers to menu items as with any other component: select the component in the Component Inspector and either use the popup menu or event properties to attach the event handler. There is, however, one difference for menu items: you can add the handler ActionListener event to any menu item by selecting the item from the Menu in the Form Window.

6.6.9. Components with Special Support NetBeans’ Java-based architecture allows it to support interactive design with components that other IDEs can’t. These components are the AWT ScrollPane and the Swing JScrollPane, JTabbedPane, JTable, JList, JDesktopPane, JDesktopPane and JSplitPane. In general, these components are used the same way as other components. The “special” support we’ll describe are NetBeans features such as the custom editor for designing JTables.

6.6.9.1. JScrollPane, ScrollPane In many cases, AWT components will pop up their own scroll bars if their content needs to scroll. An AWT ScrollPane is available, though, to add scrolling where it’s needed. Swing components, however, must be added to a JScrollPane if the content should scroll. This document won’t cover other differences between ScrollPane and JScrollPane. We’ll discuss only the JScrollPane. To use a JScrollPane, choose it from the Component Palette and click on a form. Then choose the component to be added from the Palette to the JScrollPane—and click on the JScrollPane. Remember that you can still select the underlying JScrollPane (for instance, to set its scrolling properties) by clicking on its entry in the Component Inspector.

6.6.9.2. JTabbedPane A JTabbedPane manages multiple components within its pane. NetBeans automatically gives each component its own labeled tab. When the user clicks on the tab, its component is selected and comes to the front of other components.

85 Chapter 6. Developing Java Classes

Figure 6-11. Support for JTabbedPane

The picture here shows a Form Editor window over the Component Inspector window. A JPanel was added to the JFrame, a JTabbedPane was added to the JPanel, and three

86 Chapter 6. Developing Java Classes

components were added to the JTabbedPane. By default, each tab is named for its own component. We’ve renamed the JTable, though, and also added a ToolTip that appears when the user holds the mouse cursor over the tab. Notice that each component in the JTabbedPane has its own Layout settings; this is where tab parameters (name, icon and ToolTip) are set.

Be careful where you click when adding new components to a JTabbedPane. The best place to click is in an area by the tabs which doesn’t contain other tabs. If you click on an existing tabbed component, your new component may be added to the existing component rather than to its own new tab.

6.6.9.3. JTable, JList A JTable is a grid of cells. Each cell has its own content. (The picture in the previous section shows a JTable.) A JList is similar but it has just one dimension. The special support for JTable and JList is a custom editor that controls the number of rows (and columns), the titles, object types, and so on. To open the editor, access the object’s properties (through the Component Inspector, etc.), choose the Properties tab, and click on the “...” button for the entry named “model”. The JTable editor has a tab for Table Settings and Default Values; to add an item to a JList, click the Add button in its editor.

6.6.9.4. MDI Applications: Using JDesktopPane and JInternalFrames Swing makes MDI (Multiple Document Interface, windows within windows) easy to implement. The model is like traditional computer windowing systems. In a windowing system, you have a desktop with windows on it. With the Swing MDI, you use a JDesktopPanel with JInternalFrames on it. The user can position the JInternalFrames like windows on a traditional desktop: resize, close, and minimize them. NetBeans lets you lay out and define all of this interactively. You’ll typically start with a JFrame. To it, add a JDesktopPanel. To add JInternalFrames, select them from the Component Palette and click on the JDesktopPanel, as usual. You can add other components to the JDesktopPanel—a JTable, JSlider, or whatever. But these will have their standard properties, so users can’t

87 Chapter 6. Developing Java Classes

manipulate them in the same way they could manipulate a JInternalFrame containing those components.

6.6.9.5. JSplitPane A JSplitPane has two sides. A user can move the divider between the sides to make one side bigger and the other smaller. As with other special components of this type, NetBeans allows you to manipulate it during design—for instance, to drag the divider. You may find that it’s easiest to select the JSplitPane itself by clicking on its entry in the Component Inspector.

88 Chapter 7. Advanced Operations

7.1. Using the BeanWizard

The Bean Wizard is a supporting tool that can be used to create the skeleton source code for JavaBeans. The intent is not to replace the coding that accompanies creating a JavaBean, but instead speed the process. It helps you create all the standard parts of a JavaBean, including: properties, listeners support, default constructor and BeanInfo. A JavaBean is created in three steps. Go to Tools in the Main Window and open the JavaBean Wizard. It presents three steps: 1. Name and Package. Click on Step 1, “Name and Package”, and a Dialog will appear that will prompt you to name the JavaBean and indicate the storage location. A Bean can be created on any mounted, writable file system. Click OK when finished and you will return to the Wizard Dialog. 2. Settings. Click on Step 2, Settings, and another Dialog will appear that will ask you to define the superclass and optional Bean information. You can select the superclass from the pre-defined drop-down menu or specify another name. 3. Properties. Click on Generate Bean Info to create a small class that contains information about the JavaBean (optional). If you want to associate an icon with the Bean, specify the appropriate file, URL, or relative to CLASSPATH. Click OK to return to the main Dialog and begin the final step. For the final step, click on the Properties button to declare the properties of your JavaBean. Click on New and a single-line appears that allows you to define the various properties. Select a name for the new property and a type. Select the accessibility for the property (Read-Write, Read Only or Write Only). Depending on your choice, the Wizard automatically generates the Bean’s setter and/or getter methods as appropriate. If you select the “Bounded” check-box, a PropertyChangeEvent is fired. If one or more bounded properties are generated, two new methods will be generated in the source

89 Chapter 7. Advanced Operations

code: addPropertyChangeListener and removePropertyChangeListener. These are necessary for other Beans to listen to property changes of this Bean. If you select the “Constrained” check-box, the throw statement “throws java.beans.PropertyVetoException“” will be added to the class source code. If the Bean throws this exception, it or its listeners can deny some values of the property. (See the JavaBeans specification for more detail.) If one or more constrained properties are generated, two new methods will be generated in the source code: addVetoableChangeListener and removeVetoableChangeListener. Check the Generate Variable check-box to automatically generate the variable definition. Otherwise, the following text will appear and you will have to insert the definition manually. Here’s a simple example of the property setter and getter (including the declaration of the property variable):

/** "name" property value. */ private String name;

/** Getter method for the "name" property. * @return The current value of this property. */ public String getName () { return name; }

/** Setter method for the "name" property. * @param value The new value of this property. */ public void setName (String value) { name = value; }

Add/remove properties until you are done and return to the main Dialog box. Press the Finish button of the BeanWizard to generate the source file(s) and open them in the Editor (if you selected the Bean Info option, there will be two files). You can now enter

90 Chapter 7. Advanced Operations

code and begin to compile. A successfully compiled JavaBean can be customized as described in Section 7.3.

7.2. Adding JavaBeans to the IDE

JavaBeans are Sun’s component model of Java. They’ve been widely adopted by Java developers. NetBeans IDE automates using and creating JavaBeans. It also enables the customization of particular JavaBeans, serialization of the customized state, and the use of the JavaBean with specific settings. Both visual and non-visual JavaBeans can be easily added to the NetBeans Component palette and later used in visual design. JavaBeans are distributed along with their manifests in JAR files. The NetBeans IDE includes several mounted JavaBeans components, and offers the possibility of adding many more. When you first run the IDE, you will see the TimerBean in the Beans tab on the Component Palette and three charting components from a NetBeans partner, KL Group, on the tab marked KL Group. Installing new JavaBeans is an easy way to expand the functionality of the IDE.

7.2.1. Standard Method

On the Main Window menu, choose Tools | Install New JavaBean. In the new dialog box, select the path and file name (typically *.jar) of your new JavaBean , and click Open. A list will appear with available JavaBeans. Choose one, and select Install. Next, choose where in the Component Palette you would like to place the JavaBean (under which tab) and click on Select. You will then see the new JavaBean appear under the tab you indicated, ready to use in an application. Some JavaBeans have their own icon. In cases where this is not true, NetBeans assigns a default icon to the JavaBean. To see the name of each installed JavaBean, position the cursor over the bean and a tool tip will appear.

7.2.2. Alternate Method

You can also add Beans from a JAR archive or from a local directory.

91 Chapter 7. Advanced Operations

To add a Bean from a JAR archive, go to the Main Window menu. Choose Tools | Add Jar Archive. Select the path and directory, click on the .jar file, and select Mount. The Archive then appears in the Explorer, under the Repository. Expand the node by clicking on the plus sign (or the bullet, in the Metal Look & Feel), and select the JavaBean you’re adding. Right-click on the JavaBean and choose Copy from the popup menu. Then, in the Explorer, expand the Environment section until you find the desired tab under Component Palette, select that tab, right-click and choose Paste. The new JavaBean will appear both in the Explorer and on the Component Palette on the Main Window. To add Java Beans which are not packaged in a JAR or ZIP file and/or which come only in source code, follow the directions above but use Add Directory instead of Add JAR Archive to mount the directory. Then use the same copy/paste mechanism as described above to put the Java Beans into the Component Palette. Note that the Alternate Method can also add JavaBeans that come as serialized prototypes (their filenames end with “.ser”).

7.2.3. Automatic Method

JAR files can be installed automatically each time NetBeans is started. The JAR files should be copied to a directory (folder) named “beans”. Single-user NetBeans installations (such as Windows NT) have a single beans folder under the root of the NetBeans installation. On multiuser installations (like Linux), there are two folders named “beans”: one in the shared installation folder and the other in the user portion of NetBeans. The directory/folder locations are set in the NetBeans startup script (for example, netbeans.bat on Windows systems and netbeans on UNIX systems); look for the variables NETBEANS_HOME and NETBEANS_USER. By default on Linux installations, the NETBEANS_USER directory is a subdirectory of each user’s home directory—that is, $HOME/beans. By default, all new beans in a beans directory will be installed each time NetBeans is started. By default, each bean will be put into a Palette category with the same name as the JAR file—for example, beans from a TimerBean.jar file would be added to the TimerBean Palette category.

92 Chapter 7. Advanced Operations

You can control which beans are loaded and what Palette categories they’re loaded into by adding a beans.properties file to the beans directory. There’s an example of this file below. Note that we have broken the last line (beginning “jcchart350S.beans=”) onto three lines for printing; you should enter all of it on one line of your beans.properties file:

# Netbeans - TimerBean TimerBean=Beans TimerBean.beans=com.netbeans.timerbean.Timer # KL Group - Charts jcchart350S=KL Group jcchart350S.beans=jclass.chart.SimpleChart, jclass.chart.MultiChart, jclass.chart.JCChartComponent

For each JAR file, there can be two entries in beans.properties. Neither of these entries is required.

• The first line is of the form “JARname=PALETTEname”. The left side is the name of the JAR file without the “.jar” extension. The right side is the name of the Palette category where beans from that JAR should be placed. If there’s no first line, the Palette category will have the same name as the JAR file.

• The second line is of the form “JARname.beans=beanlist”. The left side is the name of the JAR file without the “.jar” extension, followed by “.beans”. The right side is a comma-separated list of the beans which should be loaded from that JAR file. If there’s no second line, all Beans from the JAR file will be loaded. Let’s look at the sample beans.properties file above. The lines starting with a hash (#) are comments; NetBeans ignores them. There are two pairs of lines. The first pair is for the TimerBean.jar file. The first line in this pair says that Beans from this JAR should go into the Palette category named “Beans”. The second line loads the Bean named com.netbeans.timerbean.Timer. The second pair puts Beans from the jcchart350S.jar file into the “KL Group” Palette category; it loads only the three Beans named.

93 Chapter 7. Advanced Operations

7.3. Customizing JavaBeans

The Customize JavaBean action allows you to create an instance of a JavaBean, customize its properties and possibly save the customized bean as a serializad prototype. You can either use this action on a Class Data Object (.class file) or already serialized prototype (.ser file). The class must be public and have a public default constructor to use this action, and it must also be serializable to make a serialized prototypes from the customized settings. The Customization opens one or two new windows. The first window is Property Sheet, which displays properties of a newly created instance of the JavaBean. The second window is displayed only if the JavaBean is a visual component (extends java.awt.Component), and it contains the component itself. You can customize the JavaBean using the property sheet, and you can use the Serialize or Serialize As buttons to make a serialized prototype (.ser file) of the bean with current properties. Serialize As allows you to select a name and location for the .ser file, while Serialize will either save the bean into the same .ser file it originated from, overriding previous content—or place the new .ser file along the original .class file, if the bean has not been serialized yet. If you do not want to keep the customized settings, press the Cancel button to close the customization windows.

94 IV. Customizing NetBeans Developer NetBeans gives you complete control over your development environment. In this Part we describe methods to customize the IDE. You will be able to change program specific settings, adjust shortcuts, menus, toolbars and the complete appearance of the IDE.

95 Chapter 8. Control Panel

The Explorer’s Control Panel gives you access to the IDE system settings. This includes internal compiler configuration, Debugger settings, window settings, external browser or applet viewer configuration, and more. By clicking on the Show Property Sheet icon on the Explorer’s toolbar, you can see the various options for each item on the Control Panel.

8.1. System

On the System property sheet, you can control some of the more common IDE settings. As always in NetBeans, you can also set many of these from other places. For example, you can also set the Look & Feel from the Main Window View menu—and control Show Tips on Startup, which is also found on the tips dialog itself. Settings selected from the System property sheet become the defaults for NetBeans and will be consistent between sessions of NetBeans. For more advanced users, the System property sheet has a second tab, Expert, where you can set the BeanInfo Search Path and the Property Editor Search Path. These are the full names of classes where the IDE gets BeanInfo and the Property Editor.

8.2. Output Window

These settings control colors and fonts used in the Output Window.

Table 8-1. Output Window Properties

Property Description Background Background color of the Output Window Cursor Background Background color of highlighted text Cursor Foreground Color of highlighted text

96 Chapter 8. Control Panel

Font Size Size of the characters in the Output Window Foreground Default text color Jump Cursor Foreground Text color for lines of text in the Output Window that are linked to lines in the Editor Jump Cursor Background Background color for lines of text in the Output Window that are linked to lines in the Editor Tab Size Thewidthofatabstroke

8.3. Property Sheet

Here you can set the appearance and behavior of the Property Sheet.

Table 8-2. Property Sheet Properties

Property Description Disabled Property Color The text color of non-available menu options Display Writable Only Visibility (on or off) of non-available menu items Plastic Enables animation of buttons in the property sheet Property Painting Style Indicates if properties are shown as text or as pictures

97 Chapter 8. Control Panel

Sorting Mode Sets the criteria for sorting properties on the Property Sheet: by name, by type, or unsorted Value Color The text color of settings (choices) in the Property Sheet

8.4. Extensions

The Extensions setting allows you to add new extensions to be recognized as belonging to HTML or TXT file types.

8.5. Internal Compiler

Table 8-3. Internal Compiler Properties

Property Description Debug Compiler produces code with debug information Dependencies Causes recompilation of class files that the source files recursively depend on Depreciation Whether compiler treats deprecated methods as errors Encoding Character encoding used in Java sources Optimize Compiler optimizes generated bytecode Warnings Whether compiler prints warnings

98 Chapter 8. Control Panel

8.6. External Compiler

Table 8-4. External Compiler Properties

Property Description External Compiler Path to the executable Java compiler Error Expression A regular expression in Perl5 format that describes the format of the error output of specified compiler

8.7. Internal Execution

Table 8-5. Internal Execution Properties

Property Description Clear Output Tab Whether reused output is cleared from the Output Window before new execution Reuse Output Tab Whether NetBeans creates new tabs in the Output Window for each execution Run Compilation Whether NetBeans first compiles before executing a file Workspace The window to activate when executing a file (Running, Editing, Debugging)

8.8. External Execution

Table 8-6. External Execution Properties

99 Chapter 8. Control Panel

Property Description External Execution Path to the executable Java interpreter

8.9. Debugger

Table 8-7. Debugger Properties

Property Description Followed by Editor If true, the editor will keep the current line visible during debugging (the current line is the line on which the debugger is currently stopped). (default=true) Show Messages If true, additional messages about the debugger are printed to the output window. (default=true) Workspace The name of the workspace to which the IDE switches when debugger starts, or None if the workspace should not be switched. Debugger Sets the debugger executable and the debugger’s CLASSPATH.

8.10. Java Objects

The Java Objects settings allow you to enable or disable external execution, set source parser settings, and more.

Table 8-8. Java Objects Properties

100 Chapter 8. Control Panel

Property Description Background Parsing Enabled If True, a whole package is parsed on background when opened. (Warning: consumes a lot of memory) Use External Compiler If True, an external compiler is used. Use External Execution If True, applications are executed in a separate virtual machine. Parser Output Enabled If True, messages about parsing progress are written to the Output Window. Short Field Names If True, elements representing methods and variables do not display the types they represent in the Explorer. Space Before Bracket If True, a space is put before opening brackets in generated Java code.

8.11. Form Objects

The Form Objects settings affect the appearance of the grid during design time, code generation settings, and more.

Table 8-9. Form Objects Properties

Property Description Event Variable Name The name of the variable generated in the signature of the event handler method for the event object. For example, the “evt” is the variable name in “private void button1ActionPerformed (java.awt.event.ActionEvent evt)”.

101 Chapter 8. Control Panel

Grid X Size of grid for AbsoluteLayout in the X axis Grid Y Size of grid for AbsoluteLayout in the Y axis Show Grid Whether grid should be used Indent AWT Hierarchy If true, the code generated in initComponents () is indented for child components of a container. Apply Grid to Position If true, the position of components is snapped to the grid (if the grid is used). ApplyGridtoSize If true, the size of components is snapped to the grid (if the grid is used). Connection Border Color Color of components’ selection border during connection mode Drag Border Color Color of components’ drag border during dragging Selection Border Size Size (in pixels) of the boxes around a component which mark it as “selected” Selection Border Color Color of the boxes around a component which mark it as “selected”.

8.12. Applets

The Applets property sheet configures applet execution.

Table 8-10. Applets Properties

Property Description

102 Chapter 8. Control Panel

External Viewer Path to the executable external viewer Viewer Viewer to use: External Viewer, HotJava, or Internal Applet Viewer

8.13. HTTP Server

The HTTP Server property sheet controls the built-in HTTP (Hypertext Transfer Protocol or “Web”) server.

Table 8-11. HTTP Server Properties

Property Description Host Host has two settings: Any Host or Local Host. Local Host restricts access so that only the machine on which the NetBeans IDE runs is allowed access. (default=Local Host) Port The port number on which the HTTP server operates. (default=8080)

8.14. Network Options

These control the built-in Web browser.

Table 8-12. Network Options Properties

Property Description Home URL The home page for the built-in browser

103 Chapter 8. Control Panel

SMTP Server The mail server used when sending mail from the browser

8.15. Java Editor, Text Editor, HTML Editor

The Java Editor, Text Editor and HTML Editor property sheets set colors and fonts used in the editor. The table below lists common properties of the Editor:

Table 8-13. Common Editor Properties

Property Description Base Font and Colors Using the color property editor, you can choose colors based on HSV, RGB, AWT Palette, Swing Palette, and System Palette settings, and the font style (normal or italic) Font Size Displayed Size of Characters Tab Size Width of one tab stroke in the Text Editor

Predefined color schemes for the Java editor are available through the Customize button at the top of the Property sheet (just above the Base Font and Colors setting). Colors that represent the following properties can be set for the Java, Text, and HTML editors:

• Java Editor: Base Font and Colors, Breakpoint Line, Char Constant, Comment, Current Debug Line, Error Line, Float Number, GeneratedText, Hex Number, Identifier, Line Comment, Long Number, Method, Number, Octal Number, String, Tab Size, Tag, Text Selection

• Text Editor: Base Font and Color, Selected Text

• HTML Editor: Base Font and Colors, Comment, Error, Identifier, Number, String,

104 Chapter 8. Control Panel

Tag, Text Selection

105 Chapter 9. Customizing the Environment

9.1. Customizing Menus and Toolbars

You can organize all the Menu and Toolbar actions in NetBeans IDE to your preferences so that you have quick and easy access to them. From a customization point of view there are only minor differences between the Menu and Toolbars, because they are both used as generic containers to visually display a list of actions. You can add and delete existing actions to the Menu using clipboard-style operations. To add a new action to a menu or toolbar use the copy/paste operations to transfer action objects from the Explorer’s Environment | Actions hierarchy, to either Environment | Menu or Environment | Toolbar. See Section 5.2 for more information on using the Explorer.

If you delete an action from the default Menu or Toolbar (supplied with the NetBeans IDE) by copying the action from Environment | Actions (which lists all available actions) you can later put it back or add it to a different one.

To group related actions, you can add a special separator object to a menu or toolbar. Right-click the on the desired parent container (menu or toolbar) on the Explorer and select the New | Menu Separator command from the context pop-up menu. When you insert a new action in an existing menu or toolbar, you may position it among existing actions. There are two ways to change the order of actions within their parent container:

• Select the action you want to move, and use the Move Up / Move Down items in its popup menu.

• Select the parent container and choose “Change Order” from its popup menu. You will see a dialog for setting the order of all actions in the container.

106 Chapter 9. Customizing the Environment

Each menu item also has an assigned letter or digit which designates that item; it is usually the initial of some word in the item’s name. This letter or digit is marked by & in the Name property of its action.

9.2. Customizing Shortcuts

Keyboard shortcuts offer an alternative method of performing actions for users who prefer the keyboard to the mouse. These are also useful for frequently used actions, when a single keystroke is much faster and more efficient. In NetBeans IDE, you can browse current keyboard shortcuts, assign shortcut keys to actions, delete existing assignments for shortcut keys, or replace default shortcut keys with different ones. You can explore the current keyboard shortcuts using the Explorer. All shortcuts are presented as special action objects under the Environment | Shortcuts. See Section 5.2.4.4. To assign a shortcut key to an action put the cursor in the Shortcut property of the action and press the shortcut key or key combination that you want. If you press a key or key combination that is invalid, no key is displayed. Note that you cannot assign key combinations with Esc, Space, or combinations that are already being used by your operating system. If you press a key or key combination that is currently assigned to another action, that action is reported to you in a message box.

To add a shortcut to an action that is not listed under Environment | Shortcuts, you should explore action categories under Environment | Actions. Use the copy/paste operations to transfer action objects to which you want to assign shortcut keys.

9.3. Customizing the Component Palette

The Component Palette is very customizable—and it’s easy to do. Expand the Environment node of the Explorer to see the Component Palette item. Expand the

107 Chapter 9. Customizing the Environment

Component Palette item to see a list of the current Component Palette categories—these are the tabs visible in the Component Palette. Expand an individual category node to see a list of all components in that category. To create a new Palette category, right click on the Component Palette node and select New Palette Category from the popup menu. You will be prompted for the new category name. After clicking OK, the new category will appear in the Explorer listing, positioned last. You will see this new category immediately available as a tab in the Component Palette. Standard clipboard operations are available at each level of the Explorer’s Component Palette hierarchy. Individual components can be cut, copied and pasted between Component categories. You might, for example, copy the components you use most to a new category for quick and easy access. You can also cut, copy and paste Component categories. Component categories can be renamed—either by accessing the Rename item of the popup menu or using in-place renaming in the Explorer. It’s also possible to customize the ordering of component categories and the components within a category. A component category can be moved in the listing of categories via the Move Up and Move Down actions on the context menu—you will see the Component Palette tabs re-ordered as you do this. Individual components within a group can be repositioned in the same manner—or by using the Customize Order dialog. This dialog is accessible by accessing the popup menu for a Component category and selecting Change Order. This dialog lists all components in that category; using Move Up and Move Down buttons, you can re-order the contents of the category as you need. Section 7.2 explains how to add JavaBeans to the IDE.

9.4. Customizing Workspaces

Workspaces are entirely customizable via the Environment node of the Explorer. Under the Environment node you will find a Workspaces item. Expand this node to see a list of current Workspaces. These Workspace nodes can in turn be expanded to see a list of

108 Chapter 9. Customizing the Environment

currently open windows on each Workspace. Each level of this hierarchy can be cut, copied and pasted, using commands on either the popup menu or the Edit menu of the Main Window. Existing Workspaces can be renamed, again via the popup menu, the Workspace’s property sheet, or using in-place editing of the name in the Explorer. Workspace Clipboard operations act recursively; copying a Workspace copies all windows present on that Workspace. If you then paste the new Workspace to the Workspace hierarchy, these windows are copied to that new Workspace. To create a new Workspace, access the popup menu of the root Workspace node under Environment, and select New Workspace. A dialog will open, allowing you to specify the name of the new Workspace; type your name and click OK. The new item will appear in the listed tree in the Explorer, and is immediately present on the Main Window. You may need to expand the Workspace tab area on the Main Window to see your new Workspace—simply click and drag the Workspace tab divider to the right. If there are more Workspaces than visible on the Workspace tab area, left and right scroll buttons will be displayed, allowing you to scroll through all available Workspaces. You can also customize which Workspace is automatically used for Debugging and Execution. Under the Control Panel of the Explorer, right click Debugger, and select Properties. One of the properties is the Workspace - this determines the Workspace the IDE will automatically switch to on initiating a debugging session. Click on the value panel of this property (by default set to Debugging), and select the Workspace you wish from the pull down list of all current Workspaces. Similarly for execution, you can select which desktop the IDE will switch to when running an application by setting the Workspace property of the Control Panel | Internal Execution node.

109 Appendix A. Default Keyboard Shortcuts

Shortcut keys that appear in Help or in menus and dialog boxes in NetBeans are based on the United States keyboard. For example, on a U.S. keyboard, you must hold down the SHIFT key to type the < symbol. On a non-U.S. keyboard, characters may appear somewhere else on the keyboard. For example, on some keyboards, certain characters are accessible without holding down the SHIFT key, in which case, for the example above, you simply press CTRL+<. On other keyboards, characters are accessible by holding down ALTGR, in which case, for the example above, you press CTRL+ALTGR+<. Key sequences can contain function keys as well as ordinary characters. Here are the conventional names for common function keys: Table A-1. Naming Convention for Function Keys

Name Used For Left, Up, Right, Down Cursor arrow keys Backspace, Tab, Return, Delete These keys correspond to common special keys on most keyboards. End, Home, PgUp, PgDown Other cursor repositioning keys F1, F2, .. F12 Numbered function keys (across the top of the keyboard)

You can use the modifier keys ALT, CTRL, HYPER, META, SHIFT, and SUPER with function keys. The way to represent them is with prefixes in the symbol name: Table A-2. Naming Convention for Modifier Keys

Name Used For

110 Appendix A. Default Keyboard Shortcuts

Alt+ The alt modifier Ctrl+ The control modifier Shift+ The shift modifier

Thus, the symbol for the key F3 with CTRL held down is “Ctrl+F3”. When we use more than one prefix, we write them in alphabetical order; but the order does not matter in arguments to the NetBeans IDE.

These names are conventional, but some systems (especially the X Window System) may use different names.

A.1. Global Shortcut Keys

Context-Sensitive Help F1 displays help for the highlighted window.

Clipboard

Press To Ctrl+C Copy current selection into the Clipboard Ctrl+X Cut current selection into the Clipboard Ctrl+V Paste current content of the Clipboard

A.2. Form Editor Shortcut Keys

Press To Ctrl+F10 Switch to Form

111 Appendix A. Default Keyboard Shortcuts

Ctrl+F11 Switch to Editor Ctrl+F12 Switch to Component Inspector Ctrl+Shift+F10 Toggle Test Mode (form specific) Ctrl+Shift+F11 Toggle Design Mode (form specific) Ctrl+Shift+F12 Toggle Grid (global option)

A.3. Editor Shortcut Keys

Motion

Press To Up Move cursor vertically up Down Move cursor vertically down Left Move cursor one character left Right Move cursor one character right PgUp Scroll down near full screen Home Move cursor to beginning of current line End Move cursor to end of current line PgDown Scroll upward near full screen Ctrl+Left Move cursor backward until encountering the end of a word Ctrl+Right Move cursor forward until encountering the begin of a word Ctrl+Home Move cursor to the beginning of the document Ctrl+End Move cursor to the end of the document

112 Appendix A. Default Keyboard Shortcuts

Ctrl+G Go to specified line, counting from line 1 at beginning of document Ctrl+B Match brace Ctrl+Down Store current position of cursor into the position stack Ctrl+Up Pop (and go to) previous stored position on the position stack

Marking

Press To Shift+ Select text from current cursor position Ctrl+J Select word at current cursor position Ctrl+M Select current line Ctrl+A Select current document Alt+/ Extend a prefix to match following word(s) in document with same prefixing. (dynamic word completion) Alt+Shift+/ Extend a prefix to match previous word(s) in document with same prefix. (dynamic word completion)

Deleting

Press To Delete Delete character to right of cursor position, or selected text

113 Appendix A. Default Keyboard Shortcuts

Backspace Delete character to left of cursor position, or selected text Alt+Delete Delete current line Ctrl+Z Undo Ctrl+Y Redo

Formatting

Press To Tab Indent current line or selection Shift+Tab Unindent current line or selection

Search and Replace

Press To Ctrl+F Search for specified text Ctrl+H Replace some things after cursor point matching a specified text

A.4. Explorer Shortcut Keys

Press To Ctrl+N New Object Ctrl+O Open New Explorer Ctrl+S Save

114 Appendix A. Default Keyboard Shortcuts

A.5. Window Shortcut Keys

Press To Alt+0 Explore From Here Alt+1 Properties Alt+2 OutputWindow Alt+3 Debugger Window Alt+4 ExecutionWindow Alt+5 HTML Viewer Alt+6 Component Inspector Ctrl+F4 Close current window (or tab in MultiWindow) Alt+Shift+Left Previous Workspace Alt+Shift+Right Next Workspace Alt+Left Previous Tab Alt+Right Next Tab

A.6. Build Shortcut Keys

Press To F9 Compile Alt+F9 Build Alt+C Stop Compilation Alt+F7 Go to Previous Error Line Alt+F8 Go to Next Error Line

115 Appendix A. Default Keyboard Shortcuts

Ctrl+F9 Run

A.7. Debugger Shortcut Keys

Press To F5 Go (Start Debugging) Shift+F5 Finish Debugging Ctrl+F8 Toggle Breakpoint Alt+F8 Add Watch F7 Trace Into F8 Trace Over

116 Appendix B. Default Editor Abbreviations

Abbreviation Expands To sout System.out.println (" serr System.err.println (" imps import com.sun.java.swing. impa import java.awt. impj import java. psf private static final psfi private static final int psfs private static final String psfb private static final boolean Psf public static final Psfi public static final int Psfs public static final String Psfb public static final boolean ab abstract bo boolean br break ca catch ( cl class cn continue

117 Appendix B. Default Editor Abbreviations

de default: ex extends fa false fi final fl finally im implements ir import iof instanceof ie interface nu null pr private pe protected pu public re return sh short st static sw switch ( sy synchronized tr transient th throws tw throw twn throw new twni throw new InternalError();

118 Appendix B. Default Editor Abbreviations

vo void wh while Ob Object"); St String"); pst printStackTrace(); tds Thread.dumpStack();

119 Appendix C. Main Window Menus and Toolbars

C.1. Menus

This table lists and briefly describes each of the entries on the Main Window menus.

C.1.1. File Menu

• New:: Create a new object. The Templates folder will open, allowing a predefined template to be used as the basis for the new object. Available template categories are: AWT Forms, Classes, Dialogs, Other, and Swing Forms. See Section 5.4 for more information on Templates.

• Open: Open a new instance of the Explorer.

• Save: Save the current object. If there is more than one object currently open in a MultiWindow Editor, the source in the currently selected tab is saved. If there is more than one Editor Window open (that is, one or more sources have been undocked), the object in the currently selected Editor is saved. Save is disabled when no modified objects are currently open.

• Save All: Save all current open objects.

• Exit: Exit the IDE. You will be prompted to selectively save any currently open unsaved objects, discard changes, or cancel.

C.1.2. Edit Menu

• Undo: Undo last action

• Redo: Redo last action

120 Appendix C. Main Window Menus and Toolbars

• Cut: Cut selected object or text to clipboard

• Copy: Copy selected object or text to clipboard

• Paste: Paste contents of clipboard

• Delete: Delete selected object

• Find ... :Findintext

• Replace ...: Replace in text

• Goto ... : Goto line number

C.1.3. View Menu

• Explore from Here: Open a new Explorer, with the selected node as the root

• Properties: Open the Property sheet for the selected object

• Output Window: Open a new instance of the Output Window

• Debugger Window: Open a new instance of the Debugger Window

• Execution Window: Open a new instance of the Execution Window

• WebBrowser Window: Open a new instance of the WebBrowser Window

• Component Inspector: Open a new instance of the Component Inspector

• Look & Feel: List all available Look & Feels as a submenu, selecting one switches current Look & Feel. The current Look & Feel is indicated with a check mark.

• Workspaces: List of all available Workspaces as a submenu, selecting one switches to that Workspace. The current Workspace is indicated with a check mark.

C.1.4. Build Menu

• Compile: Compile selected object. If a folder is selected, compile all sources in that folder.

• Compile All: Recursively compile; compile a folder and all its sub-folders.

121 Appendix C. Main Window Menus and Toolbars

• Build: Force compilation of all classes, whether current or not.

• Build All: Recursively build; build a folder and all its subfolders.

• Stop Compilation: Stop the current compilation process.

• Next Error: Jump to the next error in the Output Window.

• Previous Error: Jump to the previous error in the Output Window.

• Set Arguments: Set command line arguments to be passed to an executed application.

• Execute: Execute the selected object.

C.1.5. Debug Menu

• Go: Initiate a debugging session.

• Finish Debugger: End the current debugging session.

• Trace Over: Trace over the method the debugger has halted at.

• Trace Into: Trace into the method the debugger has halted at.

• Toggle Breakpoint: Toggle a breakpoint on or off at the current line. The line will be highlighted blue when a breakpoint is set.

• Add Watch: Watch a variable.

C.1.6. Tools Menu

• Add Directory: Mount a new filesystem under the Repository.

• Add Jar Archive: Mount a new Jar archive as a filesystem under the Repository.

• Remove From Repository: Unmount a filesystem from the Repository.

• Install New JavaBean: Install a new JavaBean to the Component Palette.

• Bean Wizard: Open the Bean Wizard.

122 Appendix C. Main Window Menus and Toolbars

C.1.7. Window Menu

• Clone View: Clone the current window. Open a second view of the current window as a new tab on the MultiWindow.

• Undock Window: Undock the current window from the parent MultiWindow. Opens in a completely seperate and independent instance of MultiWindow.

• Dock Window: Dock selected undocked window to parent MultiWindow.

• Next Tab: Flip to the next tab in the MultiWindow.

• Previous Tab: Flip to the previous tab in the MultiWindow.

• ... Currently opened windows. All currently opened windows are listed at the bottom of the Window menu. Selecting one of these will give that window focus.

C.1.8. Help Menu

• Contents: Open the browser on the Contents page of the html documentation.

• Tutorial: Open the browser on the NetBeans Tutorials.

• NetBeans home on the Web: Open the browser, and attempt to connect to the NetBeans website at http://www.netbeans.com/ If you are using a machine which connects to the internet via a dialup modem, this may mean your modem attempts to dial and connect to your ISP. This depends on your local system configuration.

• Submit a Bug: Open the browser, and attempt to connect to the NetBeans website, and display the bug report form at http://www.netbeans.com/bug_report.html

• Tip of the Day: Display the Tip of the Day dialog which opens by default the first time your run NetBeans.

• Register: Register your NetBeans non-commercial release, converting to a commercial version. You will need the 8 character code assigned when you ordered NetBeans online.

• About: Display the NetBeans About dialog.

123 Appendix C. Main Window Menus and Toolbars

C.2. Toolbars

The four Figures below describe icons on the toolbars at the top of the Main Window. You can get the same information by holding your mouse cursor over an icon to see its ToolTip.

Figure C-1. Main Window Toolbar - Top Row

Figure C-2. Main Window Toolbar - Bottom Row

124 Appendix C. Main Window Menus and Toolbars

Figure C-3. Main Window Toolbar - New Window icons

Figure C-4. Main Window Toolbar - Form Editor icons

125 Appendix D. Actions

This table lists and briefly describes each of the actions available in the “actions pool” under Environment | Actions.

Table D-1. Data Actions

Action Description New Create a new object New (from Create a new object using an existing Template Template) Open Open Save Save current object Save All Save all open objects Save As Template Save object as a template, in the Templates hierarchy Customize JavaBean Customize properties of a JavaBean

Bean Wizard Bean Wizard

Table D-2. Edit Actions

Action Description Copy Copy selected object to the clipboard Cut Cut the selected object, keeping a copy in the clipboard Paste Paste from the clipboard Delete Delete the selected object Find ... Find in text

126 Appendix D. Actions

Replace ... Replace in text Goto ... Goto line number Undo Undo last action Redo Redo undone action Rename Rename selected object

Table D-3. System Actions

Action Description Add Directory Mount a new filesystem under the Repository Add Jar Archive Mount a Jar archive under the Repository Remove From Unmount an mounted filesystem Repository Install New Install New JavaBean to the Component Palette JavaBean Exit Exit the IDE About Display the About dialog box Register Register NetBeans non-commercial release Tip Of The Day Display the Tip of the Day dialog Help Browse the documentation in the web browser Reorder Changes order of subnodes (subcomponents) of selected item (container) Move Up Moves current item up among the parent’s children Move Down Moves current item down among the parent’s children Garbage Collect Garbage Collect

127 Appendix D. Actions

Table D-4. View Actions

Action Description Open Explorer Open a new instance of the Explorer Explore From Here Open a new instance of the Explorer, with the selected node as the root Customize Invoke a JavaBean’s Customizer Properties Open the Property Sheet for the selected object Execution Window Open a new instance of the Execution Window Debugger Window Open a new instance of the Debugger Window Output Window Open a new instance of the Output Window WebBrowser Open a new instance of the WebBrowser Window Window Previous Tab Switch to the previous tab in the MultiWindow Next Tab Switch to the next tab in the MultiWindow Next Workspace Switch to the next workspace Previous Workspace Switch to the previous workspace Windows List and switch to open windows LookFeel List and switch to Look & Feels Workspaces List and switch Workspaces Clone View Clone the current view Dock Window Dock the current window to the parent MultiWindow Undock Window Undock the current tab from the MultiWindow Close Close this window

128 Appendix D. Actions

Table D-5. Build Actions

Action Description Compile Compile the selected object Compile All Compile the selected folder and all sub-folders recursively Build Force compilation of all objects in selected folder, whether current or not Build All Build selected folder and all sub-folders, recursively Previous Error Jump to the previous error in the Output Window Next Error Jump to the next error in the Output Window Execute Execute the selected object Stop Compilation Halt the current compilation process Set Arguments Set command line arguments to pass to an application

Table D-6. Debugger Actions

Action Description Add Breakpoint Add a breakpoint Add Watch Add a watch Toggle Breakpoint Toggle selected breakpoint on or off Finish Debugger Terminate debugging session Go Initiate a debugging session Trace Into Trace into the method the debugger has halted at Trace Over Trace over the method the debugger has halted at Switch To Thread Make selected thread active (the current line in the editor displays the active thread’s position)

129 Appendix D. Actions

Suspend Suspend selected thread

Table D-7. Form Actions

Action Description Goto Source Go to the selected component in the source Goto Form Go to the selected component on the Form surface Goto Inspector Go to the selected component in the Component Inspector Component Open a new Component Inspector Inspector Events Lists events for selected component Set Layout Set the layout Test Mode Enable test mode on the form Design Mode Enable design mode on the form Show Grid Display grid on the form surface Component Palette The Component Palette

130 Recommended Reading

See the list of recommended books on the NetBeans website at http://www.netbeans.com/books_java1.html. The Java Language Specification, James Gosling, Bill Joy, and Guy Steele, Addison-Wesley, 1996. The Java Virtual Machine Specification, Tim Lindholm and Frank Yellin, Addison-Wesley, 1996.

131