Java Netbeans Tutorial Pdf

See AlsoFor information on creating and working with standard and free-form Javaprojects, see in Developing Applications with NetBeans IDE.To learn more about the IDE workflow for developing Java applications,including classpath management,see.For detailed instructions on how to compile and run a simple 'Hello World!' Application on your operating system, see the lesson of the Java Tutorials.To find information specific to the kind of applications you are developing, use the NetBeans IDElearning trail for that type of application. Each learning trail contains a series of tutorials andguides that range in scope from basic to advanced. The followinglearning trails are available:.

Gui In Java Netbeans Tutorial Pdf

Designing a Swing GUI in NetBeans IDEThis tutorial guides you through the process of creating the graphical userinterface (GUI) for an application called ContactEditor using the NetBeans IDEGUI Builder. In the process you will layout a GUI front-end that enablesyou to view and edit contact information of individuals included in an employeedatabase.In this tutorial you will learn how to: use the GUI Builder Interface, create a GUI Container, add, resize, and align components, adjust component anchoring, set component auto-resizing behavior, edit component properties.This tutorial takes about 30 minutes to complete. Contents.To complete this tutorial, you need the following software and resources.

Software or ResourceVersion Requiredversion 6.9 and more recentversion 6, 7 or 8Getting StartedThe IDE's GUI Builder makes it possible to build professional-looking GUIswithout an intimate understanding of layout managers. You can lay out your formsby simply placing components where you want them.For descriptions of the GUI Builder's visual feedback, you can use the. Creating a ProjectBecause all Java development in the IDE takes place within projects, we firstneed to create a new ContactEditor project within which to store sources andother project files.

An IDE project is a group of Java source files plus itsassociated meta data, including project-specific properties files, an Antbuild script that controls the build and run settings, and a project.xml filethat maps Ant targets to IDE commands. While Java applications often consistof several IDE projects, for the purposes of this tutorial, we will builda simple application which is stored entirely in a single project.To create a new ContactEditor application project:. Choose File New Project.

Alternately, you can click the NewProject icon in the IDE toolbar. In the Categories pane, select the Java node and in the Projectspane, choose Java Application. Click Next.

Enter ContactEditor in the Project Name field and specify the projectlocation. Leave the Use Dedicated Folder for Storing Libraries checkbox unselected.

Ensure that the Set as Main Project checkbox is selected and clear theCreate Main Class field. Click Finish.The IDE creates the ContactEditor folder on your systemin the designated location. This folder contains all of the project'sassociated files, including its Ant script, folders for storingsources and tests, and a folder for project-specific metadata. Toview the project structure, use the IDE's Files window.Creating a JFrame ContainerAfter creating the new application, you may have noticed that the SourcePackages folder in the Projects window contains an empty node. To proceed with building our interface, we need to create a Java containerwithin which we will place the other required GUI components. In this stepwe'll create a container using the JFrame component and place thecontainer in a new package.To add a JFrame container:.

In the Projects window, right-click the ContactEditor node and chooseNew JFrame Form.Alternatively, you can find a JFrame form by choosing New Other Swing GUI Forms JFrame Form. Enter ContactEditorUI as the Class Name. Enter my.contacteditor as the package.

Click Finish.The IDE creates the ContactEditorUI form and the ContactEditorUIclass within the ContactEditorUI.java application and opensthe ContactEditorUI form in the GUI Builder. Notice thatthe my.contacteditor package replaces the default package.Getting Familiar with the GUI BuilderNow that we've set up a new project for our application, let's take a minuteto familiarize ourselves with the GUI Builder's interface.Note: To explore the GUI Builder interface with an interactive demo, view the screencast.When we added the JFrame container, the IDE opened the newly-created ContactEditorUIform in an Editor tab with a toolbar containing several buttons, as shown inthe preceding illustration.

The ContactEditor form opened in the GUI Builder'sDesign view and three additional windows appeared automatically along the IDE'sedges, enabling you to navigate, organize, and edit GUI forms as you build them.The GUI Builder's various windows include:. Design Area. The GUI Builder's primary window for creating and editingJava GUI forms. The toolbar's Source button enables youto view a class's source code, the Design button allows you to view a graphical view of the GUI components, the History button allows you to access the local history of changes of the file.

Theadditional toolbar buttons provide convenient access to common commands, suchas choosing between Selection and Connection modes, aligning components, settingcomponent auto-resizing behavior, and previewing forms. Navigator. Provides a representation of all the components, bothvisual and non-visual, in your application as a tree hierarchy. The Navigatoralso provides visual feedback about what component in the tree is currentlybeing edited in the GUI Builder as well as allows you to organize componentsin the available panels. Palette. A customizable list of available components containing tabsfor JFC/Swing, AWT, and JavaBeans components, as well as layout managers.In addition, you can create, remove, and rearrange the categories displayedin the Palette using the customizer.

Java

Properties Window. Displays the properties of the component currentlyselected in the GUI Builder, Navigator window, Projects window, or Files window.If you click the Source button, the IDE displays the application's Java sourcecode in the Editor with sections of code that are automatically generated bythe GUI Builder indicated by grey areas (they become blue when selected), called Guarded Blocks. Guarded blocksare protected areas that are not editable in Source view. You can only editcode appearing in the white areas of the Editor when in Source view. If youneed to make changes to the code within a Guarded Block, clicking the Designbutton returns the IDE's Editor to the GUI Builder where you can make the necessaryadjustments to the form. When you save your changes, the IDE updates the file'ssources.Note: For advanced developers, the Palette Manager is available thatenables you to add custom components from JARs, libraries, or other projectsto the Palette. To add custom components through the Palette Manager, choose Tools Palette Swing/AWT Components.Key ConceptsThe IDE's GUI Builder solves the core problem of Java GUI creation by streamliningthe workflow of creating graphical interfaces, freeing developers from the complexitiesof Swing layout managers.

Pdf

It does this by extending the current NetBeans IDEGUI Builder to support a straightforward 'Free Design' paradigm with simplelayout rules that are easy to understand and use. As you lay out your form,the GUI Builder provides visual guidelines suggesting optimal spacing and alignmentof components.

In the background, the GUI Builder translates your design decisionsinto a functional UI that is implemented using the new GroupLayout layout managerand other Swing constructs. Because it uses a dynamic layout model, GUI's builtwith the GUI Builder behave as you would expect at runtime, adjusting to accommodateany changes you make without altering the defined relationships between components.Whenever you resize the form, switch locales, or specify a different look andfeel, your GUI automatically adjusts to respect the target look and feel's insetsand offsets. Free DesignIn the IDE's GUI Builder, you can build your forms by simply putting componentswhere you want them as though you were using absolute positioning. The GUIBuilder figures out which layout attributes are required and then generatesthe code for you automatically. You need not concern yourself with insets,anchors, fills, and so forth. Automatic Component Positioning (Snapping)As you add components to a form, the GUI Builder provides visual feedbackthat assists in positioning components based on your operating system's lookand feel. The GUI Builder provides helpful inline hints and other visual feedbackregarding where components should be placed on your form, automatically snappingcomponents into position along guidelines.

It makes these suggestions basedon the positions of the components that have already been placed in the form,while allowing the padding to remain flexible such that different target lookand feels render properly at runtime. Visual FeedbackThe GUI Builder also provides visual feedback regarding component anchoringand chaining relationships.

These indicators enable you to quickly identifythe various positioning relationships and component pinning behavior thataffect the way your GUI will both appear and behave at runtime. This speedsthe GUI design process, enabling you to quickly create professional-lookingvisual interfaces that work.First Things FirstNow that you have familiarized yourself with the GUI builder's interface, it'stime to begin developing the UI of our ContactEditor application.

In this sectionwe'll take a look at using the IDE's Palette to add the various GUI componentsthat we need to our form.Thanks to the IDE's Free Design paradigm, you no longer have to strugglewith layout managers to control the size and position of the components withinyour containers. All you need to do is drag and drop thecomponents you need to your GUI form as shown in the illustrations that follow.Note: Refer to the screencast for an interactive demo on the section below. Adding Components: The BasicsThough the IDE's GUI Builder simplifies the process of creating Java GUIs,it is often helpful to sketch out the way you want your interface to lookbefore beginning to lay it out. Many interface designers consider this a 'bestpractice' technique, however, for the purposes of this tutorial you can simplypeek at how our completed form should look by jumping ahead to the section.Since we've already added a JFrame as our form's top-level container, thenext step is to add a couple of JPanels which will enable us to cluster thecomponents of our UI using titled borders.

Refer to the following illustrationsand notice the IDE's 'drag and drop' behavior when accomplishing this.To add a JPanel:. In the Palette window, select the Panel component fromthe Swing Containers category by clicking and releasing the mouse button. Move the cursor to the upper left corner of the form in the GUIBuilder. When the component is located near the container's top andleft edges, horizontal and vertical alignment guidelines appear indicatingthe preferred margins. Click in the form to place the JPanel in thislocation.The JPanel component appears in the ContactEditorUIform with orange highlighting signifying that it is selected. After releasing the mouse button, smallindicators appear to show the component's anchoring relationshipsand a corresponding JPanel node is displayed in the Navigator window, as shown in the following illustration.Next, we need to resize the JPanel to make room for the components we'llplace within it a little later, but let's take a minute to point out anotherof the GUI Builder's visualization features first.

In order to do this weneed to deselect the JPanel we just added. Because we haven't added a titleborder yet, the panel disappears. Notice, however, that when you pass thecursor over the JPanel, its edges change to light gray so that its positioncan be clearly seen. You need only to click anywhere within the componentto reselect it and cause the resize handles and anchoring indicators to reappear.To resize the JPanel:. Select the JPanel you just added. The small square resize handlesreappear around the component's perimeter. Click and hold the resize handle on the right edge of the JPaneland drag until the dotted alignment guideline appears near the form'sedge.

Release the resize handle to resize the component.The JPanel component is extended to span between the container'sleft and right margins in accordance with the recommended offset,as shown in the following illustration.Now that we've added a panel to contain our UI's Name information, we needto repeat the process to add another directly below the first for the E-mailinformation. Referring to the following illustrations, repeat the previoustwo tasks, paying attention to the GUI Builder's suggested positioning. Noticethat the suggested vertical spacing between the two JPanels is much narrowerthan that at the edges. Once you have added the second JPanel, resize it suchthat it fills the form's remaining vertical space.Because we want to visually distinguish the functions in the upper and lowersections of our GUI, we need to add a border and title to each JPanel. Firstwe'll accomplish this using the Properties window and then we'll try it usingthe pop-up menu.To add title borders to the JPanels:.

Download

Select the top JPanel in the GUI Builder. In the Properties window, click the ellipsis button (.) next tothe Border property. In the JPanel Border editor that appears, select the TitledBordernode in the Available Borders pane. In the Properties pane below, enter Name for the Titleproperty. Click the ellipsis (.) next to the Font property, select Boldfor the Font Style, and enter 12 for the Size. Click OK to exit thedialogs.

Select the bottom JPanel and repeat steps 2 through 5, but thistime right-click the JPanel and access the Properties window usingthe pop-up menu. Enter E-mail for the Title property.Titled borders are added to both JPanel components.Adding Individual Components to the FormNow we need to start adding the components that will present the actual contactinformation in our contact list. In this task we'll add four JTextFields thatwill display the contact information and the JLabels that will describe them.While accomplishing this, notice the horizontal and vertical guidelines thatthe GUI Builder displays, suggesting the preferred component spacing as definedby your operating system's look and feel.

Note: If you create your application using JDK 6 but you need the applicationto also run on Java SE 5, you can have the IDE generate its code to use the Swing Layout Extensions libraryinstead of the classes in Java SE 6. Open the ContactEditorUI class in the GUI Editor.In the Navigator, right-click the Form ContactEditorUI node and choose Properties in the popup menu.In the Properties dialog box, change the value of the Layout Generation Style property toSwing Layout Extensions Library. Distributing and Running Standalone GUI ApplicationsTo prepare your GUI application for distribution outside of the IDE:. Zip the project's dist folder intoa ZIP archive. (The dist folder might also contain a lib folder,which you would also need to include.)To run your application, right-click the project name and select Run in the context menu. In the Run Project dialog select the main class name ( my.contacteditor.ContactEditorUI if speaking about the project you have just created) and click OK.

Your application is up and running.To run a standalone GUI application from the command line:. Navigate to the project's dist folder. Type the following:java -jar.jarNote: If you encounterthe following error: Exception in thread 'main' java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$GroupEnsure that the manifest.mf file references the currently installed versionof the Swing Layout Extensions Library.

Posted on