March 31, 2009

Connect lifelines in UML Sequence diagrams in NetBeans

NetBeans has support for UML diagrams. We can create Activity, Class, Sequence, State and Use Case diagrams. In this post we will see how NetBeans helps with creating a sequence diagram.

To start we must create a new project. We go to File | New Project. From the dialog window we select the UML category. We can create three types of projects: Platform-Independent, Java-Platform, Reverse Engineered Java-Platform. For our example we select Platform-Independent Model and click on the Next button.

We can now choose a name for our project and the location. After we filled in the values we select the Finish button.

NetBeans creates a new project for us. The project node in the Projects view shows a Diagrams node. We can right-click on Diagrams node and select New | Diagram from the pop-up menu:

A dialog window is opened and we can select the type of diagram. Here we select Sequence Diagram and press the Finish button:

Netbeans shows us a empty sequence diagram. We can add lifelines to the diagram by opening the Palette and select Lifeline and we can drop it on the diagram:

Once we have lifelines on the diagram we can connect them. We select a lifeline on the diagram and NetBeans shows a small pop-up window with options to create synchronous, asynchronous and create messages:

When we click on the Synchronous Message option a new lifeline is added to the diagram with a message interaction between the new and old lifeline:

To connect the synchronous message to an existing lifeline we must simply hold the mouse button and drag the arrow to the existing lifeline. When we release the mouse button the message interaction is created: