Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Swing or AWT for GUI ??

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am new to Java programming. I am trying to find out whether I should use AWT or Swing for the GUI part of my application. I just started to explore Swing and I like it very much. Haven't explored AWT yet.
My question is, on what basis one would determine to go with Swing or AWT. All suggestions and comments are greatly appreciated!
Thanks
Kelly
 
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only reason to use AWT is if you are targetting very old JVMs that don't support Swing. That might be the case if you are writing Applet, that is a program that will run inside a browser, and you don't want to force the end users to download a newer JVM plugin. Otherwise, just use Swing.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another very attractive alternative is SWT.
This is the Simple Windowing Toolkit used in Eclipse. It will even let you run Active X controls if you are on a Windows platform. And it can be quite a bit faster than Swing.
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is SWT supported by all JVM's?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was Facing the same problem 15 days back. I was trying to build a game of snake and its close to a finish. What i learnt is that i required more of 2d drawing and graphics for which u don't require swing, though i used it. However, if u r building a serious GUI, then swing is the best option.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Younes Essouabni:
Is SWT supported by all JVM's?


Yes. The hardware/OS may not work however, as SWT uses native services through JNI. Note that I am about as green with SWT as one can be... See www.eclipse.org for more details.
 
Kelly KMoni
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everybody for your comments!
I think I will use Swing now, may be later explore SWT also. Once again thanks for your comments.
Regards
Kelly
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok... I've been looking in SWT a bit recently... SWT is very tied to native libraries, so the Java portion of it will basically run in every JVM, but to actually have SWT run on your machine there have to be native bindings that hook into the Java code. From looking at some dev information on eclipse, it looks like it currently runs on : aix/motif, hpux/motif, linux/gtk, linux/motif, linux/qt, macos/carbon, qnx/photon, solaris/motif, win32/win32, win32-ce/win32.

From the time I've spent messing around with SWT, there are some things I like about it and some things that really annoy me about it.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Nathan Pruett:
From the time I've spent messing around with SWT, there are some things I like about it and some things that really annoy me about it.


Care to share some of those likes and annoyances? I feel the same way you do though. I think some of the widget classes are built better than Swings as far as ease of initial construction, but I would hate to try and customize anything in SWT. Plus the whole native part of SWT really takes away from JAVA considerably. In my opinion, if I were to even consider SWT, I would go with C# instead. Don't mean to hijack this thread, just adding my .02.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AWT seems so old-fashioned, if one can say that about software that still hasn't hit the double digits in age.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some things that I like about SWT -

1.) Speed...
2.) Less components to remember.
Some things that I don't like about SWT -
1.) Not MVC - just a traditional GUI toolkit that provides widgets. I know that the JFace API is supposed to address this, but documentation is kinda hard to find on it, and from what I have seen it is still partially entwined with things needed specifically for Eclipse, so some parts of it aren't generalized for stand-alone applications.
2.) Some things need explicit deallocation.
3.) Every time you construct a component, you have to pass in the component's container, and a style built out of constant int values in the SWT class OR'ed together. (So if you want a component to move to a new container, or change certain aspects of it's style, you have to create a new component.) Also, abstract classes tend to be preferred over interfaces in the API...
4.) Untyped listeners - Generic Listener class and generic Event class. When you add one of these to a component you specify what type of event they listen to using yet more constant int values from the SWT class. Higher level event listeners are also provided, but at a low level all event handling that is core to SWT is actually done using untyped listeners and the event constants. Makes me wonder if custom events would seem as 'snappy'... plus makes removing/replacing specific listeners harder.
5.) People drool over the 'exactly native look and feel' thing, but you lose some control over how your GUI actually looks or possibly works. You might tweak your program to look great under Windows XP, but some of the styles or attributes may not be available on other platforms, so you end up with a really crappy or unusable app on other platforms.
5.) Deployment would actually be more difficult, as you would have to make sure the right shared library was installed on the user's system for your SWT program to run. What about versioning problems (AKA 'DLL Hell') after there are multiple revisions of the SWT libraries out there?
6.) In general, it feels like you are sacrificing flexibility for speed. And I wouldn't describe the speed increase for most apps as 'blazing' or anything. You do get faster load times and the GUIs seem 'snappier', but if you are having "really bad" performance problems with Swing, it is usually due to mis-using Swing APIs, or a bad design that would produce equally bad performance under SWT (i.e. 'We need a tree that displays 10,000,000 nodes, all at the same time, and that updates all of them based on separate background threads!').

I don't mean to sound as anti-SWT as this post actually sounds... it's just that so many people are praising SWT for 'faster GUIs' and 'native look and feel' that they are forgetting some of the drawbacks.
 
Trust God, but always tether your camel... to this tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic