Swing better than Awt?

J

jb

dolphin:
Better for what purpose?

Xiaochuan Fang:
AWT is too simple, while SWing is too slow.

AWT is not simple, but featureless. It might get complicated when you
try to customize it a lot.

I use swing just for esthetic pleasure of using so well planned
library, and because it is very easy to learn, to use, and to
customize. But my apps aren't commercial, and my users (well there's
only few :)) don't need very opiimized things.
 
L

Lew

jb said:
dolphin:

Better for what purpose?

Xiaochuan Fang:

AWT is not simple, but featureless. It might get complicated when you
try to customize it a lot.

I use swing just for esthetic pleasure of using so well planned
library, and because it is very easy to learn, to use, and to
customize. But my apps aren't commercial, and my users (well there's
only few :)) don't need very opiimized things.

SWT is not standard enough for me.

Swing is only slow if your Swing app is poorly designed. Admittedly, it's
tricky to get right because of the rules about the EDT, and the Motif/OpenLook
style of coding takes some getting used to, and of course, it really helps if
you are comfortable with Java listener idioms, but if programming was easy
we'd be out of work.

I don't know that anyone is too impressed with Java user-interface libraries,
but Swing definitely can get the job done.

Swing does not depend on the platform to implement its behaviors the way that
AWT does. Most of Swing's behaviors are pure Java.

-- Lew
 
C

Christian

Michael said:
No, not the old fairy-tale again.

Bye
Michael

Is it really a fairy tale?

from my understanding of swing (I haven't really used it)

swing hides the fact from you that an os usually only allows one single
Gui-Thread that you have to use when you interact with the gui ...


don't know how swing does interaction then..
either you can't interact directly with os ressources .. so swing only
lets the os paint, but all resources that are interacted with are java
only..
or swing magically transfers your actions into the right thread for
execution..


any of these seems to be non trivial ...
if for example the os- developpers took a lot of care that the gui
interaction thread is very responsive to the user .. java would throw
that advantage away if the use their own threads..

transfering actions from a normal thread to the gui thread may be done
in a non optimal way for your application ...

I am just guessing ...
but from what I heard swing seems to be a tool getting faster and faster
with every java version and less distinguishabel from the native gui ...
though if it is like I guessed above .. there will always be a border
swing can't cross ... where you need to force more work on the
programmer for getting the native gui like in swt/jface

Christian
please don't lapidate me
 
L

Lew

Is it really a fairy tale?
Yes.

from my understanding of swing (I haven't really used it)
swing hides the fact from you that an os usually only allows one single
Gui-Thread that you have to use when you interact with the gui ...

And exposes the fact that Swing only allows one single Java Event Dispatch
Thread (EDT) that you have to use when you interact with the GUI.

-- Lew
 
M

Michael Rauscher

Christian said:
Is it really a fairy tale?

Yes, it is.

Swing is based on AWT. The main difference between AWT and Swing is that
Swing paints components (and manage their states) by itself while AWT
let the native system paint them.

Consequences:

1. Swing is a tick slower than AWT.
2. Swing isn't thread-safe.
3. It's easier to produce Swing apps that aren't responsive.

ad 1) It's just a tick, so it's far away from being "too slow".

ad 2) As a result there's the single-thread rule:
Swing components can be accessed by only one thread at a time.

Note, that there are no guarantees that AWT is thread-safe.
It's a result of the underlying system.

ad 3) One can easily block the EDT - in both, Swing and AWT.
It's just that one can recognize a blocked EDT in a Swing
application immediately.

Let's compare what happens if one blocks the EDT in Swing
and AWT. To do this, we'll have a look at a GUI containing
one button that - if pressed - blocks the EDT for about
5 seconds.[1]

Swing: the button keeps pressed for 5 seconds.
In fact, the whole content of that window will not
get repainted within the 5 seconds.

AWT: the button returns to the normal state immediately.

So, how can one recognize a blocked EDT in a AWT app?

Resize the Window while the EDT is blocked. Both, the Swing
and the AWT app will not resize the button until
the 5 seconds are over.

In real apps one can't continue until the EDT is not blocked
anymore - in both, Swing and AWT.

Bye
Michael

[1] Sample application (negative), to call use
java SwingAWT [mode]

If mode is not given, the Swing version will run.
If mode is swing, the Swing version will run.
If mode is anything other, the AWT version will run.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SwingAWT {
private ActionListener listener = new ActionListener() {
public void actionPerformed( ActionEvent e ) {
try {
Thread.sleep(5000);
} catch ( InterruptedException ie ) {}
}
};

private Frame frame;
private Component button;

private void initAWT() {
button = new Button("Block EDT");
((Button)button).addActionListener( listener );
frame = new Frame("SwingAWT - AWT");
}

private void initSwing() {
button = new JButton("Block EDT");
((JButton)button).addActionListener( listener );
frame = new JFrame("SwingAWT - Swing");
}

public void createAndShowGUI( boolean awt ) {
if ( awt )
initAWT();
else
initSwing();

frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
frame.dispose();
}
});
frame.add( button );
frame.pack();
frame.setVisible(true);
}

public static final void main( String args[] ) {
final boolean awt =
(args.length < 1 || "swing".equals(args[0])) ?
false : true;

EventQueue.invokeLater( new Runnable() {
public void run() {
new SwingAWT().createAndShowGUI(awt);
}
});
}
}
 
C

Chris Uppal

Michael said:
No, not the old fairy-tale again.

I'd say it's far from being a fairy-tale. I agree that (what with improvements
inside AWT/Swing /and/ general speedups of machines) it is no longer as true as
it used to be, but it wasn't and isn't a complete myth.

It's like claiming that the Thames is polluted. That is true today, but not in
anything like the way that the poor river was polluted a 50 or 100 years ago.
Then it was so true that you'd build your life around that truth (not live near
the bad bits of the river and so on). These days, you wouldn't actually
/drink/ it, but not everyone who jumps in comes away with a health problem...

Swing is slow in the same sort of sense. It's /too/ slow, but it's no longer
so bad that I'd automatically avoid using a Swing/AWT app just for that reason.

(And no, before anyone mentions it, I'm /not/ talking about the [lack of]
startup speed -- that's a different issue IMO.)

- chris
 
M

Mark Thornton

Chris said:
Swing is slow in the same sort of sense. It's /too/ slow, but it's no longer
so bad that I'd automatically avoid using a Swing/AWT app just for that reason.

In my opinion a Swing application needn't be /too/ slow but it may take
an experienced Swing developer to achieve that result. For example many
people would have trouble displaying a 100MB text document in Swing.
However with a careful choice of Document implementation this can
perform very well -- you can use the normal JTextArea to handle all the
display details, all the bottlenecks were in the Document implementation
(some of these have been fixed since I last experimented).

Mark Thornton
 
M

Michael Rauscher

Chris said:
I'd say it's far from being a fairy-tale. I agree that (what with improvements
inside AWT/Swing /and/ general speedups of machines) it is no longer as true as
it used to be, but it wasn't and isn't a complete myth.

It's like claiming that the Thames is polluted. That is true today, but not in
anything like the way that the poor river was polluted a 50 or 100 years ago.
Then it was so true that you'd build your life around that truth (not live near
the bad bits of the river and so on). These days, you wouldn't actually
/drink/ it, but not everyone who jumps in comes away with a health problem...

Swing is slow in the same sort of sense. It's /too/ slow, but it's no longer
so bad that I'd automatically avoid using a Swing/AWT app just for that reason.

In the same way SWT, my PC and internet connections are too slow. Your
point is nearly always true for nearly anything.

I already mentioned that Swing is a tick slower than AWT and of course
it would be nice if Swing would get faster.

NB: A few years ago I tried both NetBeans and Eclipse under Linux. A
situation where SWT was much slower than Swing. But I would say that
neither SWT nor Swing is too slow.

Bye
Michael
 
S

Sherm Pendley

Richard Maher said:
Does anyone handcraft this stuff anymore or is it all generated
code now anyway?

I'd say that learning to handcraft GUI code is valuable even if you end up
using a GUI builder tool for production work. The experience you gain from
writing the code by hand will give you a better understanding of what the
tool is creating for you.

sherm--
 
R

Richard Maher

Hi Chris,
but not everyone who jumps in comes away with a health problem...

Ah, but many do! Speaking as one who came away with a bruised/broken coccyx
after jumping off Richmond Bridge two summers ago (the day before it reached
100F) I can testify that it's still not a pleasant experience :) I didn't
hit the bottom even though the tide was way out and, as a local, I should've
known better, it was just the sheer majesty and height of that 45ft leap and
tsunami-inducing entry that did the damage. But then there's that Viles
disease, hacked up bodies in suitcases, numerous discharges from Iselworth
treatment works, and the seemingly endless detritus that most of London
seems to deposit in it, and only an idiot would jump in! That's alcohol for
ya :-(

Anyway WRT Swing -vs- AWT, as a beginner I've been using AWT 'cos I thought
it was a simpler yet still functional interface. Is that wrong? Did Swing
supplant AWT? Is there a library better than Swing? I imagine technology
hasn't stood still since the gridbag layout, but where should one invest
there time? Does anyone handcraft this stuff anymore or is it all generated
code now anyway?

Regards Richard Maher

Chris Uppal said:
Michael said:
No, not the old fairy-tale again.

I'd say it's far from being a fairy-tale. I agree that (what with improvements
inside AWT/Swing /and/ general speedups of machines) it is no longer as true as
it used to be, but it wasn't and isn't a complete myth.

It's like claiming that the Thames is polluted. That is true today, but not in
anything like the way that the poor river was polluted a 50 or 100 years ago.
Then it was so true that you'd build your life around that truth (not live near
the bad bits of the river and so on). These days, you wouldn't actually
/drink/ it, but not everyone who jumps in comes away with a health problem...

Swing is slow in the same sort of sense. It's /too/ slow, but it's no longer
so bad that I'd automatically avoid using a Swing/AWT app just for that reason.

(And no, before anyone mentions it, I'm /not/ talking about the [lack of]
startup speed -- that's a different issue IMO.)

- chris
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Richard said:
Anyway WRT Swing -vs- AWT, as a beginner I've been using AWT 'cos I thought
it was a simpler yet still functional interface. Is that wrong? Did Swing
supplant AWT? Is there a library better than Swing? I imagine technology
hasn't stood still since the gridbag layout, but where should one invest
there time?

I believe that >95% uses Swing and not AWT today if it is possible.

Note that it is not possible if you have to support applets running
with old MS or NS JVM's.
Does anyone handcraft this stuff anymore or is it all generated
code now anyway?

The tradition in the Java world is handcoded GUI's.

Arne
 
A

Andrew Thompson

....
(usage of Swing)
Note that it is not possible if you have to support applets running
with old MS or NS JVM's.

Apparently here was a 'swing.jar' (or
similar) available for attaching to
even Java 1.1 projects, though given
it was at least a couple of hundred Kb,
I never felt it was justified to deliver
it with an applet that was ..I think the
biggest applet I wrote was around 40Kb of
bytecodes, just for the addition of buggy
(think 'pre 1.2') Swing components to the
end user.

This is mostly a moot point, of course,
since the original Swing jar would still
not support a lot of the things that were
either introduced, or significantly improved,
in Swing for later J2SE releases.

Andrew T.
 
R

RedGrittyBrick

Richard said:
Anyway WRT Swing -vs- AWT, as a beginner I've been using AWT 'cos I
thought it was a simpler yet still functional interface. Is that
wrong?

AWT is simpler, it is functional. I ignored AWT and just started with
Swing.
Did Swing supplant AWT?

Yes. Broadly speaking.
Is there a library better than Swing?

For specialised and restricted values of "better" there is SWT etc.
There would be a different answer for J2ME. For server based Java apps
the GUI could be HTML or even AJAX I guess.
I imagine technology hasn't stood still since the gridbag layout,

It hasn't.
but where should one invest there time?

In the areas most relevant to the type of application you are interested
in creating. Maybe you should get a broad overview of the Java platform
before deciding which areas to invest some time in?
Does anyone handcraft this stuff anymore

Yes. Some do.

or is it all generated code now anyway?

No. Some is not.
 
J

John W. Kennedy

Richard said:
Anyway WRT Swing -vs- AWT, as a beginner I've been using AWT 'cos I thought
it was a simpler yet still functional interface. Is that wrong?

It's simpler in that it has fewer features, but for non-trivial jobs,
Swing is frequently easier to /use/.
Did Swing
supplant AWT?

Not entirely. Swing uses some basic parts of AWT to get its job done,
and event handling is still done using the improved AWT event system
that was introduced in Java 1.1. But, in general, yes.
Is there a library better than Swing?

If you need to support versions of Java older than Swing, AWT is better.
(But versions of Java older than Swing are all obsolete.) If you want to
write a plug-in for Eclipse, SWT is better. But, in general, Swing is
much more powerful.
> I imagine technology
hasn't stood still since the gridbag layout,

Yes and no. GridBagLayout is still probably the most powerful tool for
general-purpose layouts, but there are some new tools to simplify
certain common cases. (Layouts are another instance of AWT features that
are still used with Swing.)
but where should one invest
there time? Does anyone handcraft this stuff anymore or is it all generated
code now anyway?

There are a bunch of layout-design tools, but none of them seem to be
likely to take over the world anytime soon. There are also some things
in Swing that are self-contained solutions where AWT would have needed a
layout, such as toolbars.

--
John W. Kennedy
"The pathetic hope that the White House will turn a Caligula into a
Marcus Aurelius is as naïve as the fear that ultimate power inevitably
corrupts."
-- James D. Barber (1930-2004)
* TagZilla 0.066 * http://tagzilla.mozdev.org
 
C

Christian

If you need to support versions of Java older than Swing, AWT is better.
(But versions of Java older than Swing are all obsolete.) If you want to
write a plug-in for Eclipse, SWT is better. But, in general, Swing is
much more powerful.

Swing may be more powerful alone .. but swing contains some things
that are not representing gui-widgets, but also mappings from model to
the gui... in swt this is strictly devided.. swt only represents the
gui the average os has ... if you need help modelling you datamodel to
the gui then there is jface..

though from what I have seen of swing I would think swing is still more
powerful than swt and jface combined, but this separation is a strength
that will make it easier for swt to develop in the future...
and if you need some functionallity of swing that swt/jface doesn't have
... for example rendering text with the help of html .. then you can just
embedd swing in swt..

But swing is definately much easier to deploy..
You don't have to get different libs for every os..


.. my experience so far..
Christian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top