Swing Explorer tips

Here are short tips helping to understand some of the Swing Explorer's features and concepts.

1.Install and Run IntelliJ IDEA plug-in for Swing Explorer

2. Install Eclipse plug-in for Swing Explorer

3. Use Eclipse plug-in for Swing Explorer

4. Installing NetBeans plug-in

5. Using NetBeans plug-in

6. Navigate to sourcecode directly from Swing Explorer

7. Find a source code where a component is added into a container

8. Observe a component's preferred size

9. Launching Swing Explorer from a command line

Install and Run IntelliJ IDEA plug-in for Swing Explorer

Swing Explorer Plug-in was tested with IntelliJ IDEA version 11.x.x.

1. Download latest version of Swing Explorer plug-in for IDEA from here

2. Open Plug-In Manager and use "Install plugin from disk..." button to select the downloaded filehere

3. After installation an additional Run menu item becomes available in the pop-up menu of a main class. It starts your main class with Swing Explorer.

Select Archive

Install Eclipse plug-in for Swing Explorer

Swing Explorer Eclipse plug-in provides integration with Eclipse IDE. The plug-in is compatible with 3.2.x and 3.4.x versions of Eclipse. To install the plug-in please download a swex-eclipse.zip file from here and use it as Archive update site in your Eclipse. Different Eclipse versions may require a bit different installation steps but the idea is the same. Below there are instructions for installing Swing Explorer plug-in for Eclipse 3.4.2

1. Download latest version of Swing Explorer plug-in for Eclipse from here

2. Select Help->Software Updates menu in your Eclipse

3. In the "Available Software" tab press "Add Site..." button

Add Site

4.Press the Archive button, select your downloaded ZIP file and press OK.

Select Archive

5. Select Swing Explorer component like it is shown below and press "Install" button

Install

6.Proceed with further Wizard steps. You will have to accept license agreement and restart Eclipse.

Use Eclipse plug-in for Swing Explorer

Eclipse plug-in makes easier launching of your application with Swing Explorer. Additionally it provides a sourcecode navigation possibility. After installing Eclipse plug-in, the Swing Explorer run configuration should become available in the Run/Debug dialogs. It is configured pretty similar to common Java applications:
1. Use Run->OpenRun Dialog menu to open it
2. Right click Swing Explorer item and select the "New" item like it is shown on the screen below.
New launch configuration
3. Fill the parameters like it is shown below.
Configure and run
4. Some additional arguments, classpah entries are configured configured in the same way as for any standard Java application. After you press "Run" button  Swing Explorer will be automatically launched together with your application.

Installing NetBeans plug-in

Swing Explorer Eclipse plug-in provides integration with NetBeans IDE. The plug-in is compatible with 6.x versions of NetBeans. To install the plug-in do the following:

1. Download the latest NetBeans module from here.

2. In your NetBEans IDE open Tools->Plugns dialog.

3. In the Downloaded tab press "Add Plugins..." button and select the downloaded module in the file dialog.

Add NetBeans plugin

4. Press "Install" button and proceed with further wizard's installation steps. You will have to accept license etc. After you finish the steps the plug in is ready to use.

Using NetBeans plug-in

NetBeans plug-in makes easier launching of your application with Swing Explorer. Additionally it provides a sourcecode navigation possibility. After installing the plug-in you will have an additional menu item "Run with Swing Explorer" available in the "Projects" tree popup menu when you right click on a project. Selecting this menu item launches your project's main class together with Swing Explorer.

Run With Swing Explorer

Navigate to sourcecode directly from Swing Explorer

When Swing Explorer is launched using an IDE plug-in it is possible to use direct navigation to sourcecode. For instance when clicking the "src" button in the Player tab Swing Explorer automatically opens the source file and selects appropriate code line in your IDE.
IDE integration with Player

Find a source code where a component is added into a container

Swing Explorer has an "Addition trace" tab at the bottom. It is useful when you have a quite complicated UI code and want to find a source code line where a component was added into a container. It contains the full stack trace of the instruction responsible for adding a selected component into a container. The stack trace is automatically changed/refreshed when you select some other component in the tree or on the display area.

Looking at the "Addition trace" shown on the figure below it is easy to figure out that "JLabel(Name:)" component was added into a container in the 34 line of the PersonalDataFrame3.java file. The stack trace elements have hyperlinks. Clicking a hyperlink opens the selected source line in the IDE.
Attention: The hyperlink navigation functionality is available only when Swing Explorer is launched using and IDE plug-in.

Addition trace

Here is the source code fragment from the sample application:

27: public class PersonalDataFrame3 extends JFrame {
28:         public PersonalDataFrame3() {
29:                 JPanel contentPane = new JPanel(new BorderLayout());
30:                 setContentPane(contentPane);
31:                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
32:                 
33:                 JPanel pnlName = new JPanel(new GridBagLayout());
34:                 pnlName.add(new JLabel("Name: "), new GridBagConstraints(0, 0, 1, 1, 0, 0, 
                                                              NORTHWEST, NONE, new Insets(0, 0, 0, 0), 0, 0));
35:                 pnlName.add(new JTextField("John"), new GridBagConstraints(1, 0, 1, 1, 1, 0, 
                                                              WEST, HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
36:                 // ...
37:         }
38: }

Additionally you can dump this stack trace to the console using the right click menu on a selected component like it is shown on the screenshot below.
Addition trace dump

Observe a component's preferred size

Sometimes it is important to know a preferred size of a Swing component to estimate how does it impact the real component's size when the component has been layed out. To view the preferred size it is necessary to switch on the "Show Preferred size" checkbox. After that you will see an additional rectangle showing the preferred size when you move mouse over a component. On the figure below the preferred size of the "Female" radio button is shown as a black rectangle.

Show preferred size

Launching Swing Explorer from a command line

To launch Swing Explorer from IDE it is recommended to use IDE plugins. Currently plug-ins for NetBeans and Eclipse IDE are available. In case you want to use Swing Explorer without IDE or just execute it manually you have to download the following two Jar files from:
    swexpl.jar - Swing Explorer UI
    swag.jar - Instrumentation agent
The files can be downloaded from here. The instrumentation agent optional. It is needed when Event Dispatch Thread violation monitoring or Addition trace functionality is necessary. If you don't need it you can leave with just swexpl.jar. To launch full version of Swing Explorer with your application please download Jar files mentioned above and use the following command:
    java -javaagent:swag.jar -Xbootclasspath/a:swag.jar -cp swexpl.jar;<your_class_path> org.swingexplorer.Launcher <your_main_class>
for instance for SwingSet the command line looks like this:
    java -javaagent:swag.jar -Xbootclasspath/a:swag.jar -classpath swexpl.jar;SwingSet2.jar org.swingexplorer.Launcher SwingSet2