Screencast: Developing Swing with JavaRebel

June 12th, 2008 by Jevgeni Kabanov
We prepared a short screencast that demonstrates how easy it is to develop Swing applications with JavaRebel. We used the simple Metalworks example (a multiwindow mail client mockup) that comes with the Java SDK and played around with adding fields and buttons.

We start by launching the application with “-noverify -javaagent:javarebel.jar” added to the VM params in the Eclipse launch profile. We first add new field “BCC”, which immediately appears in a new window. We then also add a Send button, which first does nothing. We then proceed to add a listener that points to the new send() method. After we make the body of the method to show a message box it is visible in both new and old windows that had a listener added. Finally we refactor the class adding a field and showing its value in the message box. Note that old instances have the field, but it’s initialized to null, while the new instance works properly.

Since most of the Swing initialization will happen only once, a nice trick we found for making a component reinit itself is using the JavaRebel SDK as follows:

[java]
ReloaderFactory.getInstance().addClassReloadListener(
new ClassEventListener() {
public void onClassEvent(int eventType, Class klass) {
if (MyClass.class == klass) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
reinit();
}
});
}
}
});
[/java]

One Response to “Screencast: Developing Swing with JavaRebel”

  1. Swing links of the week: June 15, 2008 : Pushing Pixels Says:

    [...] Kabanov has a screencast on changing the source code of a running Swing application with JavaRebel. Looking at the [...]

Leave a Reply