Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

Create Account  |  Retrieve Password

SWT, Swing, or AWT - Which Is Right For You?

Posted by Zonk on Sun Feb 26, 2006 03:50 AM
from the choose-wisely dept.
An anonymous reader writes "Why is there more than one Java GUI tool kit? The best answer is that one size does not fit all, nor is there a one-size-fits-all GUI tool kit to be invented soon. Each tool kit offers advantages and disadvantages that make selecting one more appropriate, given your needs and intended audience. Read descriptions of each tool kit's basic features, and the pros and cons of using each."
+ -
story
This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More
Loading... please wait.
  • by killjoe (766577) on Sunday February 26 2006, @04:01AM (#14803101)
    You don't have to go with those, there are java bindings for everything!> QT, wxWindows, even curses!.

    Pick the one you like!
    • by penguin-collective (932038) on Sunday February 26 2006, @04:25AM (#14803141)
      Yeah, trouble is, no matter which you pick, you'll still be programming from Java.
    • by ultranova (717540) on Sunday February 26 2006, @04:26AM (#14803144)

      You don't have to go with those, there are java bindings for everything!> QT, wxWindows, even curses!.

      Pick the one you like!

      Pick something besides AWT/Swing, and your users need to download and install it. That lessens the chances that they pick your program, or that they will even be able to pick it - after all, every third-party library needed decreases the chances that all of them have been ported to the target platform.

  • by dood (11062) on Sunday February 26 2006, @04:18AM (#14803125)
    It should be SWT vs Swing. There's hardly a reason to use the plain AWT when there's Swing (a much more powerful library built on top of AWT).
    • Oh, really? No reason at all? About a year ago, I had to work on a project [altsoftware.com] for Christie Digital [christiedigital.com] through Alt Software. The project was about building software that controlled video input from multiple devices into the same computer (I tested with 70 simultaneous inputs, this was possible because the hardware used overhead busses from input cards to output cards,) and video output onto rear-projector TV Video Walls. The software had to be designed in a way that supported multiple different platforms (wind
  • My six word summary (Score:3, Interesting)

    by MillionthMonkey (240664) on Sunday February 26 2006, @04:27AM (#14803145)
    SWT : buy
    Swing: hold
    AWT : sell

  • Huh? (Score:5, Informative)

    by Yaztromo (655250) <yaztromo@jsyncmanager . o rg> on Sunday February 26 2006, @04:38AM (#14803174) Homepage Journal
    Why is there more than one Java GUI tool kit? The best answer is that one size does not fit all

    That hardly answers the original question -- it's true, but it doesn't answer the statement in question. That would be like saying:

    Why is the sky blue? The best answer is that 1 + 1 = 2

    The reason why there are three toolkits is simply: originally, Sun developed AWT. AWT was introduced with Java 1.0 as a way to obsfucate the drawing of common GUI widgets on a variety of platforms, using the native widget set. Unfortunately, this was problematic for many platforms, and wasn't very flexible.

    Thus, Sun developed Swing. It supported more widgets, and did a lot of its own drawing in order to appear and generally layout the same across different platforms.

    Swing, unfortunately, has some design limitations, not the least of which is that it is very memory hungry. When IBM decided to "port" VisualAge for Java from being a Smalltalk-based product over to using Java, they found that Swing wasn't up to the task, so they decided to develop their own widget toolkit, called SWT. SWT wasn't exactly intended for use outside Eclipse, mind you -- it's just that many developers decided to use it as such.

    So we're left with a bit of a GUI mess on our hands in the Java world -- one I really wish would be fixed. Swing works, but it can be slow and memory intensive. SWT is non-standard, and requires a platform-specific module which users may not already have installed (which means either you have to tell them to download and install it, or you have to create a bunch of installers for different platforms to allow them to run your SWT-based application).

    That is why we have thre different toolkits. For all intents and purposes, the bulk of AWT is deprecated and shouldn't be used for its widgets. It is simply difficult to get rid of due to the number of legacy applications out there which are still using it, and which will probably never be updated to use Swing.

    And then there is Cocoa-Java...

    Yaz.

      • Re:Huh? (Score:3, Informative)

        Honest question - what do you mean by saying that SWT is 'nonstandard'?

        It's not part of the Java standard from Sun. That isn't to say that SWT itself doesn't conform to its own defacto SWT standard -- it's just not part of the Java standard. It is my understanding that legally, IBM can't advertise SWT as being "Java", and can't even technically call Eclipse a Java IDE (even though it does the job just fine).

        Sun needs to take a look at what Apple has done with Interface Builder and Cocoa. It should th

      • Re:Huh? (Score:5, Informative)

        by Yaztromo (655250) <yaztromo@jsyncmanager . o rg> on Sunday February 26 2006, @08:18AM (#14803554) Homepage Journal
        I don't think it is fair to use the swing memory argument anymore. It is really something that has been worked on.

        I agree that there have been improvements, but I'm sorry -- I do think it's fair to continue to take Sun to task for this still.

        A quick example -- the jSyncManager [jsyncmanager.org], my most popular OSS application. It can be run in either GUI or console mode. In both, the engine code is identical -- only the user interface differs. Firing it up in GUI mode uses about 35MB of RAM on my Mac OS X 10.4.5 based PowerBook. Firing it up in console mode uses ~15MB of memory.

        That's a 20MB difference, and that is just after start-up. The GUI has a single window, with three menus, and a total of 11 menu items. There are NO widgets in the window -- instead it just has a graphic (it's meant to be run minimized -- the menus allow access to help, configuration items, and the log window). And yet that uses 20MB.

        Activating every menu item that bring up a GUI dialog once, with the exception of the Help subsystem (which uses JavaHelp) brings it up to ~45MB of memory usage. Bringing up everything including JavaHelp once causes it to use ~55MB of memory. That is 40MB of GUI, and it is all absolutely trivial stuff -- excluding JavaHelp, it's probably less than 50 widgets all together.

        True -- I have 1.25GB of RAM in my system, so 40MB is barely even noticed. Still, this is an absolutely trivial GUI (the complexity is in the data synchronization engine -- again, this application is meant to be a "fire-and-forget", run it in the background program which handles PalmOS data synchronization, and doesn't typically require any user input other than configuration).

        For a more complex comparison, I fired up "Tapear", a clinical document management system that is part of another Open Source project I work on known as OpenTAPAS [opentapas.org]. It has only one window, but has hundreds of widgets of all types in it, with multiple tabs for a whole variety of different view types. It doesn't have much of anything in terms of an "engine", as it retreives all of its data from a remote database. After loading it up and opening up a single patient, it uses 80MB of RAM -- more than even my entire IDE (Xcode) uses by 25MB.

        (I should note that all the above tests were done with the latest release version of Java 1.5 for Mac OS X (PPC)).

        One more example -- Limewire 4.9 uses ~75MB of RAM with no transfers.

        Sorry, but Swing is still quite memory hungry. Can you imagine running all of your applications as Java applications? Improvements are being made, but I think there is room for further improvements in this regard.

        Yaz.

          • Re:Huh? (Score:4, Informative)

            by Yaztromo (655250) <yaztromo@jsyncmanager . o rg> on Sunday February 26 2006, @11:37PM (#14806315) Homepage Journal
            I doubt that it really uses 20MB. It just appears to use 20MB. What's almost certainly really happening is that it's mapping 20MB more of virtual memory, of which very little is actually used. For example, if the program needs a class or two from some JAR, the JVM will mmap() the entire JAR file, reserving virtual address space for all of it, even though only the pages that actually get read will be faulted in and consume real RAM. So several megabytes of virtual address space has been "consumed", but only a few KB of actual RAM is used.

            I'm quite aware of how to properly profile memory for Java applications, and yes, there is a 20MB difference in actively used memory. The virtual memory claimed is siginificantly higher than what I quoted -- where it's using ~35MB of real memory, the process is claiming a whopping 453MB of virtual memory (which of course isn't allocated at all, and thus doesn't really affect much of anything performance or RAM wise). Opening all four possible dialogs at once bumps that memory usage up to closer to 50MB.

            I have a pile of Java memory profiling tools that all agree with this memory usage assessment. Now it's possible that the low level implementation on Mac OS X is more hungry than on some other platforms, but in my testing this is relatively equivalent to running it on Linux and Windows.

            Sorry, but Swing is memory hungry. It tends to show in complex applications, which is one reason why I've kept the jSyncManager as simple as possible in terms of GUI.

            Yaz.

      • Re:Huh? (Score:3, Insightful)

        I have never heard of anyone who did not use Swing because of its memory usage.

        Are you new around here? ;)

        Admittedly, I use Swing. I don't avoid it because of its memory requirements, but they are a source of continued concern to me. Admittedly, the issue doesn't get as much attention these days as RAM continues to become ever more inexpensive, but there is still serious room for improvement. Read my other posting here on this subject [slashdot.org] for some examples.

        Swing is flexible, and can create some nice GUI

  • by tonywestonuk (261622) on Sunday February 26 2006, @04:43AM (#14803183)
    .... let me post two opposing sides of the swing vs swt debate:

    Swt is crap [hacknot.info]

    and

    Swing is crap [ahmadsoft.org]
  • by kwerle (39371) <kurt@CircleW.org> on Sunday February 26 2006, @04:49AM (#14803191) Homepage Journal
    Each tool kit offers advantages and disadvantages that make selecting one more appropriate, given your needs and intended audience.

    Having used them, I'm pretty sure that each just has a different set of disadvantages.

    Spoiled after 15+ years of [NeXT|Open|GNU]Step/Cocoa, I guess.
  • None of the above. (Score:5, Interesting)

    by seebs (15766) on Sunday February 26 2006, @04:54AM (#14803200) Homepage
    Buoy [sourceforge.net] is your friend. It's built on top of Swing, but it's actually sanely usable. I recommend it on the grounds that it is the only Java GUI toolkit I have ever used that did not leave me longing for the sweet embrace of death. Developing an application using Buoy is substantially less painful then stabbing yourself in the eye with a fork. In the world of Java GUI development, this is high praise indeed.

    Seriously, though. If you are doing GUI work in Java, but your actual goal is to get something else done, and you would like the GUI toolkit to take less than 80% of your development effort, use Buoy. It's not "dumbed down"; it's just SANE.
  • Swing (Score:4, Interesting)

    by Anonymous Coward on Sunday February 26 2006, @05:09AM (#14803223)
    I've never used SWT, but I have quite extensive experience in both AWT and Swing, as well as many other GUI toolkits, including two cross platform toolkits of my own for a commercial product that shall be anonymous in this post.

    In my opinion the Cocoa AppKit on OS X is perhaps the most elegant overall. The problem is that with Cocoa AppKit, the common things are extremely simple and easy to do, but the more uncommon things can be quite tricky. With Swing, the most common things are still simple, but take considerably more code than with Cocoa. But when you get to something more advanced where you want to get some custom behavior (maybe dealing with drag & drop on some custom widget, or perhaps you want to customize the selection model on a tree widget or somethign similar), then Swing suddenly becomes much easier to work with compared to the otherwise simple Cocoa.

    AWT isn't really an option over Swing in my opinion. It's there for historical reasons, and as the low-level API for Swing. Swing is built on top of AWT, after all.

    There are a couple of larger problems with Swing:

    1) Performance can suck if you don't know exactly what you're doing.
    2) Making it behave exactly like you want often requires you to know it quite well.
    3) It is quite large and complex, and can seem overwhelming to learn.

    The performance problem is actually the biggest reason Java is still perceived as being slow by many people who aren't familiar with it. Developers often shoot themselves in the foot with threading issues, and it makes Swing UI's seem slow and poorly responsive. Also, because of poor understanding of the more advanced layout managers, it's also not uncommon to see Swing based UI's that just... look sort-of wrong. They don't look like native apps. Not because of look & feel issues of the widgets, but because of margins and paddings around widgets being wrong. You have problems like buttons being too large, text areas being right up to the edge of the window, quick-hack looking layout of widgets in preferences-style windows that have a large number of widgets, and so on. You often also see things like the app not painting itself during window resize drags, default window icons, inconsistent font sizes, and so on. Many of these are simply caused by people not fully knowing the Swing API and not knowing how to do things properly. It's not that you can't do them right, it's that people don't know the tool thoroughly. In my opinion, this is directly caused by the API being overwhelmingly large for many developers. While it gives Swing its incredible flexibility, it also indirectly is the cause for many of its problems.

    Sun is tackling the performance problem from one end. They are working on accelerating a lot of the lower level graphics API (image drawing, primitive drawing, etc.) with OpenGL and DirectX. This helps a lot in many situations, but it doesn't help in the cases where people do 3 second tasks in a UI event callback method. Likewise, the ugly-UI problem is being helped by better IDE's (Matisse in Netbeans 5, for example) and by Java SE 6's (Mustang) better handling of system look and feels.

    Still, there's a long way to go. But Swing is getting better every day, and it's the standard choice that works on all platforms, and it IS possible to do excellent UI's with it even today. You just need to learn it well. My recommendation is to read the API reference until you know it by heart. Then study the Swing source code to see how things work under the hood.
  • by BortQ (468164) on Sunday February 26 2006, @05:42AM (#14803276) Homepage Journal
    I give much credit to SWT for putting a fire under swing and forcing them to improve. The current Swing is much better then it was a few years ago. It can take some long years before a toolkit matures and best practices for its use come out. I feel like that is happening now with Swing. If some of the SwingLabs stuff gets put into the real pipe that would be lovely.

    SWT seems to be encountering some growing pains as it really starts to cover everything that a toolkit must. I wish them luck in pulling through even stronger (on all platforms please). SWT certainly has had a strong start.

    It seems like there are enough Java developers out there to support 2 GUI toolkits. I think in the long run this can only be good for Java as a whole. If people don't like one they can stick with Java and swap out the toolkit. If one eventually becomes "the one" then it will only be because the other pushed it to be the best it could.

  • Question (Score:5, Interesting)

    by Orlando (12257) on Sunday February 26 2006, @07:34AM (#14803479) Homepage
    This may be a dumb question, but why can't Java just provide access to the existing desktop GUI (Windows, OSX, QT, whatever) rather than re-inventing the wheel with it's own set of widgets that inevitably don't look or behave like native apps?
    • Re:Question (Score:4, Informative)

      by LeninZhiv (464864) * on Sunday February 26 2006, @08:24AM (#14803567)
      You can use Java with GTK, Cocoa, or native Windows toolkits. The question then becomes, why Java programmers are not interested.

      The basic reason for this is, your application's GUI becomes completely unportable, and you suddenly have little reason for having written it in Java in the first place instead of the platform's "standard" language (C, Objective C, or C#).

      A "middle way" is to do what SWT does and wrap the native widgets with a generic API. This creates a "lowest common denominator" problem, however, since you inevitably have to stick to only using those widgets which all your target platforms have...
  • AJAX (Score:3, Insightful)

    by SoupIsGood Food (1179) on Sunday February 26 2006, @07:38AM (#14803486)
    The correct answer is, "None of the Above."

    Before you invest a lot of time, effort and money crafting a GUI front-end for your application, you should really stop and consider that you may not need one.

    If your app is basically a way of querying a database on a server deep in the bowels of the computer room, you should be coding the interface as a web application. Especially now that AJAX is on the scene... modern AJAX tools and a Java backend can put together some very powerful applications that don't have the same development and deployment costs that an executable on every desktop would.

    AJAX isn't a cure-all, and not likely to help much if you're interacting with local datasets with lots of processing horsepower (as in an imaging program like the Gimp or a sound editing program) or constructing a platform-independant application that's mostly self-contained (like a game or a p2p client.)

    It is great for things like CRM applications, scheduling tools, inventory tools and ticket-monitoring... stuff that need to read and set values in a database somewhere. It's even good for applications that were previously in the domain of the workstation and the PC, like lightweight data visualization tools and PIMs.

    What's more, the development cycle of an application that only needs a copy of IE or Firefox to run will be a lot easier for you, the user/customer and the poor slobs in IT who would need to come up with a deployment plan, and =then= an upgrade plan when rev 1.2 comes out.

    SoupIsGood Food
    • I'll agree with you to a point. What you're talking about is, really, the old fat vs thin client approach. Fat clients (a la Swing, SWT, whatever) makes loads of sense if:
      • you're in control of your clients/endpoints (i.e. sys mgmt not an issue)
      • you have skinny network connectivity
      • you have sophisticated and/or performance-sensitive GUI

      A thin client approach makes sense if:

      • you are NOT in control of your endpoints
      • you have adequate connectivity
      • you have simple GUI and linear dialogue flows
      • sub-second per
  • by caseih (160668) on Sunday February 26 2006, @01:20PM (#14804329)
    As the article mentioned, Swing is a very good, advanced toolkit with some advantages over SWT. A project called SwingWT is an implementation of Swing using SWT, giving you a much faster GUI that looks and feels more native. So you can do all your development and initial testing with pure Swing, then swich the UI classes to SwingWT for a native look and feel on the hosts that support SWT. Seems like an interesting idea to me.
  • by borgheron (172546) on Sunday February 26 2006, @01:58PM (#14804453) Homepage Journal
    This is the trouble with Java.. there are too many GUI libraries. Standardize on one and forget the rest. It seems that when an environment is born without one, it's destined to search for the perfect gui framework forever.

    As an example of an evironment which has never had this problem, take Mac OS X, it has had AppKit since the day it was created... and it will never see another major gui framework. Ah, yes... you can say but there's GTK and others available on the Mac, but they are not a threat to the *MAIN* AppKit framework... (they do, in fact use AppKit, so they aren't an outright replacement).

    Intersting dilemma...

    But... to get back on topic, I prefer SWT, it's faster, and it blends more readily with the native environment than the others.

    GJC
          • Java programmer here. There is a Free project called Mono which is implementing most of .NET, even the non-standard WinForms is also emulated and they are offering alternatives with other GUI toolkits like Gtk#. Mono targets many platforms. Again, I'm a Java programmer and even I know this. I think diversity's good. Competition's good. What do you think the main driver is behind JSF? Yep, .NET's WebForms.
        • Have you actually abstracted resize functions into a library? That'd be a sight to see.

          The reason no one does that is that all layouts are different, with different things that need to be resized or not, under different conditions. Like, if my window gets too small, this thing needs to be collapsed entirely. Or, as a window gets bigger, another thing only needs to be resized up to a point, then it is more useful to put the extra space somewhere else.