How can I use Swing 1.1.1 in the VCE in VAJ versions 2.0 and 3.0 (non-Java2 version)?

Scott Stanchfield

VisualAge for Java 2.x and 3.0 (JDK 1.1 version) support Swing 1.0.3. But the most recent VAJ 3.0 EA and VAJ 3.5 both support Java2, which is at or past Swing 1.1 level.

Note: IBM does not provide support for this -- it should work, but isn't official.

Please email Scott Stanchfield at thetick@jguru.com if any part of this gives you grief.

This tip describes how you can use Swing 1.1.1 in VisualAge for Java versions that are JDK 1.1.

VisualAge currently needs to do some special processing to support Swing:

  • VisualAge explicitly "hardcodes" knowledge that JFrame, JDialog, JApplet and JWindow use a "contentPane" to hold their children. There are also some classes, like JTabbedPane, that the VCE treats specially by adding extra properties to its children's property sheets. This knowledge is associated with class names
    • com.sun.java.swing.JFrame
    • com.sun.java.swing.JApplet
    • com.sun.java.swing.JDialog
    • com.sun.java.swing.JWindow
    • com.sun.java.swing.JTabbedPane
    • com.sun.java.swing.JScrollPane
  • Layout manager support is not generic; VisualAge hardcodes the layout managers, including com.sun.java.swing.BoxLayout

Setting up Swing 1.1.1

First you need to import the Swing 1.1.1 classes into VisualAge for Java.

  1. Get the Swing distribution from Sun
    See http://java.sun.com/products/jfc to obtain this
  2. Install Swing on your computer. Make sure you install the "full developer release"
  3. Start up VisualAge for Java
  4. Create a project called "Swing"
  5. Import JAR file swingall.jar. This file will be in the base directory in which you installed Swing.
    1. Make sure you unselect any com.sun.java.swing.* classes in the jar file
    2. Make sure you import all resources (you can exclude the com/sun/java/swing ones if you wish.
    3. When asked, create a new VCE beans palette category called Swing 1.1.1
    4. Add all imported beans to the Swing 1.1.1 category
  6. VERSION the Swing project as "sas 1.1.1" (you can replace "sas" with whatever you want -- those are my initials)
    This is important so you won't have any problems if IBM wants to add "Swing 1.1.1" to your workspace.

After you've set up,  you're ready to use Swing 1.1.1 in VisualAge for Java!

Writing Swing 1.1.1 Applications

I haven't done too much testing with this (about an hour), but so far it seems to work well.

There are three ways to write Swing 1.1.1 applications in VisualAge for Java:

  • Write code by hand - this approach will work, but can be a lot of work...
  • Use the VCE with the "old" Swing classes to initially develop your GUI, then replace all references to com.sun.java.swing with javax.swing. You'll lose the Visual Design unless you make the change in another package, or outside of VisualAge for Java
  • Use the newly imported Swing beans except JFrame, JApplet, JDialog, JWindow and JScrollPane. (If you find others, let me know)
    • Note -- I'm working on some nice workarounds for using these visually
  • Use any layout except BoxLayout -- if you use BoxLayout you'll need to rename the generated names.
    • I'm working on a "CustomLayoutPanel" to get around this...

By simply avoiding the "unusable classes" you can create your GUIs. Then write another class by hand to wrap the VCE-created GUI in a JFrame, JDialog, JApplet or JWindow:

public class FunkyApp extends JFrame {
  public FunkyApp() {
    setContentPane(new ThingCreatedInVCE());
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
  }

  public static void main(String[] args) {
    new FunkyApp().setVisible(true);
  }
}

Make sure you add the "Swing" project to the CLASSPATH for your application (the JFrame)!

You can deal with JScrollPane by adding one to the GUI in the VCE, then setting up an initialize() connection to call its setViewportView() method, passing the thing to stick in it.

Known problems with Swing 1.1.1 components

  • JFrame, JDialog, JApplet, JScrollPane won't let you add components
  • JTabbedPane won't switch tabs or set component tab names, icons, etc
    • you need to use the Beans List to add components

Feel free to add more FAQ entries for other problems!

 

See also

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.