SWT vs. Swing: API
Today two major and incompatible UI libraries are available for Java developers: SUN’s Swing and IBM’s SWT (which is used for the Eclipse platform). Often it is claimed that SWT is the faster and more stable solution. Since in our projects Swing was fast and stable enough a point of major interest was the API: What is easier and more flexible to program. I did a little experiment based on the very good SWT tutorial “Using the Eclipse GUI outside the Eclipse Workbench, Part 1: Using JFace and SWT in stand-alone mode” from Adrian Van Emmenis. I took the SWT file explorer consisting mainly of a tree and a table from the tutorial and programmed an equivalent Swing file explorer. The code can be downloaded for the SWT-File-Explorer and the Swing-File-Explorer.
The main differences between the two explorers:
- The Swing explorer needs with 249 LOC about 30% more lines of code than the SWT explorer with 192 LOC.
- Setting the properties of SWT widgets is follows the C style with expressions like SWT.HORIZONTAL SWT.NULL. Since the properties are simply integers there is a (small) lack of type safety.
One (subjective) word about performance: When using the two explorers I can hardly notice any difference. Only when directories contain very many files the SWT explorer seems to be a bit faster.
Entry filed under: Uncategorized.