Archive for March 19th, 2005

Mar 19 2005

ImageDescriptor problem on JFace actions?

Published by Kerry under Uncategorized

I found what seems to be an issue with setting an jface.resource.ImageDescriptor for an jface.Action class.  I have a few standard button bar images that I was going to use in my application.  When I first set the image for the action, I thought I was doing something wrong.  I set the image originally, like this:

public ExitAction() extends Action {
 
    public ExitAction() {
        super( “E&xit@Ctrl+X“, ImageDescriptor.createFromFile( “images\\close.gif“ ) );
        setToolTipText( “Exit Application“ );
    }
}

Unfortunately, this produced a small red square on the button and on the menu item that the ExitAction was assigned to.  I checked the image thinking it was corrupt, but all was well.  After doing a little snooping, I found that you can also create an ImageDescriptor from a swt.graphics.Image.  I changed the code to look like this:

public ExitAction() extends Action {
 
    public ExitAction() {
        super( “E&xit@Ctrl+X“ );
        setToolTipText( “Exit Application“ );
        Image image = new Image( Display.getCurrent(), “images\\close.gif“ );
        setImageDescriptor( ImageDescriptor.createFromImage( image ) );
    }
}

This produces the desired results.  I am not sure why the first way of setting the image for the action did not work, but every tutorial that I have gone through and even the code in Apress’ The Definitive Guide to SWT and JFace do it like I did it in the first code fragment above.

Technorati Tags: , ,

One response so far

Mar 19 2005

Using Ant to build an executable Jar file

Published by Kerry under Uncategorized

Boy… I am tired.  It is 3:09 pm in the afternoon and I have only been up for just over three hours today.  I dove deep into SWT and JFace last night.  I am really enjoying JFace at this point.  It really makes building a GUI application with SWT so much easier.

Anyway, at some point during the night, for whatever reason (can’t remember now), I decided to setup a build.xml file for Ant.  I did this for two reasons:  1)  I wanted to learn more about using Ant and 2) I wanted to see if I could setup a build properly for the SWT/JFace application that I am working on.

The setup of the build.xml to do a clean compile and to build a simple jar file was quite easy.  The problem came in, however, when I tried to build an executable Jar.  I never could get things to work correctly.  I kept getting a message about java not being able to find the main class when I tried to launch the jar.

A little after 6:00 am this morning, I finally decided that I should get some sleep.  I guess that helped, because after sitting here for the past 30 minutes looking at it again, I figured it out.  Well, I figured it out by accident.  :)

I did a little reading on the Sun Developer Network forums and something made me look at another executable jar file that I know I have on my computer.  When I took a look at the manifest in the jar, I noticed that all of the files listed on the Class-Path entry were in the same deployment directory as the executable jar.  I had tried putting them in a path on the classpath and putting them in the jar, but that never did work this morning.

So, I said what the heck and copied the appropriate external jar files that I knew the project needed into the directory where my jar file was located.  Now, mind you, this is the same jar that had just 30 seconds earlier given me that same “Cannot find the main class” error message.  After copying the files, I tried to launch the jar again and to my surprise, my application came right up.  Sweet!

I hate that I have wasted most of a Saturday, but I have definitely learned a lot about Ant and creating executable jar files in the past 18 hours.

Technorati Tags: , , ,

No responses yet