SWT is my preferred graphics library for client-side Java. The threading model is sensible, performance is good, set of built-in UI functions is comprehensive, and the native implementations have a good look and feel that fits in with the OS.
SWT is a native graphics library. It makes use of the operating system's existing GUI framework which is GTK on Linux and Unix, Cocoa on MacOS, and Win32 / Win64 calls on Windows. This means there is a different jar for each OS and each architecture (32 or 64 bit).
If you are building for multiple operating systems and/or architectures then you need a way to specify which SWT jar should be used.
One way to do this is to provide multiple launchers (Windows .bat files or shell scripts) which set the classpath accordingly in each one. You could also detect the OS/Arch during installation and deploy the correct launcher that way.
If you don't want to go down that route then there are 2 ways to dynamically select the correct SWT jar at runtime:
1) Use a custom classloader which inspects the OS and JVM. This is fine except you will need to specify the custom classloader in your call to the java binary:
java -Djava.system.class.loader=com.chrisnewland.classloader.CustomLoader -jar ChrisApp.jar
Your custom classloader is now responsible for loading everything (3rd party classes, resources, images ... and this might be more than you bargained for. You could also run in to the headache of remembering which classload is responsible for what classes and resources and end up with memory leaks.
2) The second option, presented here, uses a little bit of naughty reflection to call a protected method on the URLClassloader to insert the URL of your jar (can be a local file path or a remote URL) at runtime.
If you are happy to break strict object-oriented guidelines to simply solve a common problem then read on!
Let's say that your application is supported on 32 and 64 bit versions of Windows and Linux. You will need to bundle 4 SWT jars with your application. Name them as follows:
lib/swt_win_32.jar
lib/swt_win_64.jar
lib/swt_linux_32.jar
lib/swt_linux_64.jar
Now here is some code to query the OS and architecture and return the jar filename according to the jar naming convention above:
public static String getArchFilename(String prefix)
{
   return prefix + "_" + getOSName() + "_" + getArchName() + ".jar";
}

private static String getOSName()
{
   String osNameProperty = System.getProperty("os.name");

   if (osNameProperty == null)
   {
       throw new RuntimeException("os.name property is not set");
   }
   else
   {
       osNameProperty = osNameProperty.toLowerCase();
   }

   if (osNameProperty.contains("win"))
   {
       return "win";
   }
   else if (osNameProperty.contains("mac"))
   {
       return "osx";
   }
   else if (osNameProperty.contains("linux") || osNameProperty.contains("nix"))
   {
       return "linux";
   }
   else
   {
       throw new RuntimeException("Unknown OS name: " + osNameProperty);
   }
}

private static String getArchName()
{
   String osArch = System.getProperty("os.arch");

   if (osArch != null && osArch.contains("64"))
   {
       return "64";
   }
   else
   {
       return "32";
   }
}
Calling it with
String jarFilename = getArchFilename("lib/swt");
will get the correct jar filename at runtime for the system.
Now use the following reflection code to invoke URLClassloader.addURL(URL url) to add this jar to the classpath at runtime (make sure you invoke this code to add the jar before the first class that imports an SWT class is loaded!).
public static void addJarToClasspath(File jarFile)
{
   try
   {
       URL url = jarFile.toURI().toURL();
       URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
       Class<?> urlClass = URLClassLoader.class;
       Method method = urlClass.getDeclaredMethod("addURL", new Class<?>[] { URL.class });
       method.setAccessible(true);        
       method.invoke(urlClassLoader, new Object[] { url });            
   }
   catch (Throwable t)
   {
       t.printStackTrace();
   }
}
So here is the calling code to dynamically select the correct SWT jar:
File swtJar = new File(getArchFilename("lib/swt"));
addJarToClasspath(swtJar);