Swing

Swing Application Framework

  • JSR 296 - Swing Application Framework - complement to swing that takes care of some common app items. Looks kind of cool.
  • Location of Mac prefs files: /Users/username/Library/Application Support/appname where appname is what you set Application.id to.

I like this framework. Great examples. We are using it at Orba Nova for our dashboard application. It allowed me to focus on building the app rather than building the framework stuff like properties, storing window location, prefs, etc. I like it quite a bit.

Example - Create a 2nd window

None of the examples had this, so I had to google/did around. It's simple once you figure it out. My use case: show the "routes" window when the Edit => Routes menu item chosen:

    private FrameView routesWindow;
    
    @Action
    public void routes()
    {
        if (routesWindow == null)
        {
            JFrame frame = new JFrame();
            frame.setName("routes");
            frame.setContentPane(new RoutesPanel());
            routesWindow = new FrameView(this);
            routesWindow.setFrame(frame);
        }
        show(routesWindow);
    }

Building Swing Application Framework

Note: I use 64 bit Java 6 and installed it in c:/dist/java/jdk1.6.0_07. 64 bit Java 6 doesn't support a number of things, JNLP being one of them, so I also have the 32 bit Java 6 JRE installed in c:/dist/java/jre6.

To get it to build from the command line, I did the following:

  • Download AppFramework-1.0.3 to my c:/junk/swing directory and unzip it.
  • From the c:/junk/swing/AppFramework-1.03 dir (the extract of the src jar)
  • cp c:/dist/java/jre6/lib/javaws.jar lib - build-time-only dependency on java webstart (only available in 32 bit Java 6, so I copied from my local 32 bit JRE install)
  • cp c:/work/dev/repos/junit/junit/3.8.1/junit-3.8.1.jar lib - for unit testing
  • Modified nbproject/project.properties to set these classpaths:
# JDD - changed this path (we copied file from Java 6 JRE since not in Java 6 JDK)
#jnlp.classpath=${java.home}/lib/javaws.jar
jnlp.classpath=lib/javaws.jar
# JDD - created entry for junit
libs.junit.classpath=lib/junit-3.8.1.jar
  • Then ant works fine.
  • java -cp "dist/AppFramework.jar;build/classes;lib/swing-worker.jar" examples.SingleFrameExample5 - how to run one of the examples

You can remove the dependency on the included swing-worker.jar if you are using Java 6. Edit these files and change the imports like so:

  • src/org/jdesktop/application/Task.java
  • src/org/jdesktop/application/TaskMonitor.java
// JDD - replace with standard Java 6 SwingWorker
//import org.jdesktop.swingworker.SwingWorker;
//import org.jdesktop.swingworker.SwingWorker.StateValue;
import javax.swing.SwingWorker;
import javax.swing.SwingWorker.StateValue;

And adjust the classpath in project.properties:

javac.classpath=\
    ${jnlp.classpath}:\
    ${osx.jnlp.classpath}:\
    ${libs.swing-layout.classpath}
# JDD - commented out after changing source code to use java 6 SwingWorker
# ${file.reference.swing-worker.jar}
  • Run ant clean; ant to rebuild
  • java -cp "dist/AppFramework.jar;build/classes" examples.SingleFrameExample5 - notice the easier classpath.

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-18) was last changed on 03-Feb-2009 13:35 by donohoe [RSS]