gamelan
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
New
 
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!




Developer Jobs

Be a Commerce Partner














 


Developer News -
iPhone Users Just Want to Have Fun    August 26, 2008
Oops! I Fixed the Linux Kernel    August 22, 2008
Jim Zemlin: The New Center of Linux Gravity    August 21, 2008
Microsoft's Novell Investment Tops $340M    August 20, 2008
Free Tech Newsletter -

SWT Programming with Eclipse
By Koray Guclu

Go to page: Prev  1  2  3  4  5  6  Next  

5. Running SWT Applications Outside of Eclipse

To run the application without using Eclipse, the swt.jar library must be in your classpath, and the java.library.path enviroment variable must be set properly. Depending on the host platform, the appropriate native library file must be available. For the Windows platform, you can do the following to make the native library configuration for your application:

  1. Put swt.dll in the same directory as the program.
  2. Put swt.dll in the JAVA_HOME\bin\ directory.
  3. Put swt.dll in the c:\windows\system32 directory.

javac classpath c:\swt\swt.jar HelloWorld.java
Java classpath c:\swt\swt.jar;. Djava.library.path=c:\swt HelloWorld
The java.library.path is the required environment variable for the JNI. If you don't set this environment, your DLL class is not accessible. In that case, the application cannot run properly and throws an exception.

SWT libraries
Swt libraries are available under the Eclipse plug-in directory. If you want to get the SWT libraries without downloading the whole Eclipse package, it is possible to download a single SWT library under the http://www.eclipse.org/downloads directory.

6. SWT Packages

The SWT consists of the following main packages. Definitions of the packages are taken from the Eclipse API documentation. You can find the API documentation on the Eclipse Web site.
org.eclipse.swt: contains classes that define constants and exceptions that are used by SWT classes. An SWT package consists of three classes: SWT, SWTException and, SWTError. The SWT will probably be your favorite class because it contains constants for SWT libraries such as keyboard, error, color, layout, text style, button etc. constants.
org.eclipse.swt.widgets: Contains most core SWT widget components, including the support interface and classes.
org.eclipse.swt.events: Defines typed events, listeners and events, that SWT components use. This package contains three different groups of classes: Listener interfaces, Adapter classes, and Event class.
org.eclipse.swt.dnd: Contains classes for drag-and-drop support of the SWT widgets.
org.eclipse.swt.layout: Contains classes providing automated positioning and sizing of the SWT widgets.
org.eclipse.swt.print: Contains classes providing print support for the SWT widgets.
org.eclipse.swt.graphics: Package provides the classes which implement points, rectangles, regions, colors, cursors, fonts, graphics contexts (that is, GCs) where most of the primitive drawing operations are implemented, and images including both the code for displaying them and the public API for loading/saving them.

7. Dialogs

Dialog implementations are native. That is to say, dialogs, like widgets, are platform components. Dialogs in SWT are derived from the Dialog abstract class. A dialog is not a widget but it can contain widgets.

Figure 2. Dialog class hierharcy.

There are different types of dialogs available. Some dialogs can have specific properties. A a dialog can be used as shown in Source 2.

Source 2. MessageBox example
MessageBox messageBox = 
  new MessageBox(shell, SWT.OK|SWT.CANCEL);
if (messageBox.open() == SWT.OK)
{
  System.out.println("Ok is pressed.");
}

Each dialog's open() method returns different types. For instance, the MessageBox dialog returns int from the open() metod. Therefore, one must write different conditions to handle the return value for each dialog.

ColorDialog shows a color selection pallet. It returns an RGB object from return method.

DirectoryDialog enables you to select a directory. It returns A String from THE open() method. The returning value is the selected directory. It is also possible to set additional filters to filter the directories.

The Font dialog enables a user to select a font from all available fonts in the system. It returns a FontData object from the open() method.

FileDialog enables a user to select a file. Additionally, you can set an extension filter, path filter, and filename filters. This dialog has the styles shown in Table 1:

Table 1. SWT Dialog style bit constants
SWT.OPEN Shows Open button in the dialog
SWT.SAVE Shows Save button in the dialog

PrintDialog enables a user to select a printer before starting a print job. It returns a Printer Data object from the open() method.

The MessageBox dialog is used to give feedback to the user. You can combine different styles by the | operation as shown in Source 3.

Source 3. MessageBox example
 MessageBox messageBox =
   new MessageBox(shell,
    SWT.OK|
    SWT.CANCEL|
    SWT.ICON_WARNING);
 messageBox.setMessage("www.korayguclu.de");
 messageBox.open();

The resulting message box of the above example is shown in Figure 3.

Figure 3. MessageBox dialog.

Available button constants are listed below. A combination of different buttons can be made by using the | operation. The SWT framework builds the dialog depending on the style bits. The button constants are: SWT.ABORT, SWT.OK, SWT.CANCEL, SWT.RETRY, SWT.IGNORE, SWT.YES, and SWT.NO.

Table 2 shows a list of available icons to be used by dialogs.

Table 2. SWT icon style bit constants
SWT.ICON_ERROR
SWT.ICON_INFORMATION
SWT.ICON_QUESTION
SWT.ICON_WARNING
SWT.ICON_WORKING

Go to page: Prev  1  2  3  4  5  6  Next  

Previous article: A First Look at Eclipse Plug-In Programming
Next article: Constructing SWT Layouts


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Other Java Archives








JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Intel PDF: Virtualization Delivers Data Center Efficiency
Intel eBook: Managing the Evolving Data Center
Microsoft Article: BitLocker Brings Encryption to Windows Server 2008
Symantec eBook: The Guide to E-Mail Archiving and Management
Microsoft Article: RODCs Transform Branch Office Security
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
Avaya Article: Advancing the State of the Art in Customer Service
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Avaya Article: Avaya AE Services Provide Rapid Telephony Integration with Facebook
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Seminar: Efficiencies in Hardware/Software Virtualization
HP Webcast: Disaster Recovery Planning
Go Parallel Video: Performance and Threading Tools for Game Developers
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
IBM TCO eKIT: Your IT Budget is Under Attack, Get in Control
IBM Energy Efficiency eKIT: Learn How to Reduce Costs
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Microsoft Article: Silverlight Streaming--Free Video Hosting for All
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
HP Demo: StorageWorks EVA4400
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES