Swing better than Awt?

Discussion in 'Java' started by dolphin, Mar 18, 2007.

  1. dolphin

    dolphin Guest

    Hi !Swing better than Awt?How do you think?
     
    dolphin, Mar 18, 2007
    #1
    1. Advertising

  2. On Mar 18, 9:12 pm, "dolphin" <> wrote:
    > Hi !Swing better than Awt?


    Define 'better'.

    >..How do you think?


    Why not start the thread rolling, by
    giving your views, first?

    Andrew T.
     
    Andrew Thompson, Mar 18, 2007
    #2
    1. Advertising

  3. dolphin дµÀ:
    > Hi !Swing better than Awt?How do you think?
    >

    AWT is too simple, while SWing is too slow.
    I like SWT/JFace.
     
    Xiaochuan Fang, Mar 18, 2007
    #3
  4. dolphin

    jb Guest

    dolphin:
    >>Hi !Swing better than Awt?How do you think?


    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.
     
    jb, Mar 18, 2007
    #4
  5. dolphin

    Lew Guest

    jb wrote:
    > dolphin:
    >>> Hi !Swing better than Awt?How do you think?

    >
    > 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.


    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
     
    Lew, Mar 18, 2007
    #5
  6. Xiaochuan Fang wrote:
    > dolphin дµÀ:
    >> Hi !Swing better than Awt?How do you think?
    >>

    > ... while SWing is too slow.


    No, not the old fairy-tale again.

    Bye
    Michael
     
    Michael Rauscher, Mar 18, 2007
    #6
  7. dolphin

    Christian Guest

    Michael Rauscher schrieb:
    > Xiaochuan Fang wrote:
    >> dolphin дµÀ:
    >>> Hi !Swing better than Awt?How do you think?
    >>>

    >> ... while SWing is too slow.

    >
    > 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
     
    Christian, Mar 18, 2007
    #7
  8. dolphin

    Lew Guest

    dolphin wrote:
    >>>> Hi !Swing better than Awt?How do you think?


    Xiaochuan Fang wrote:
    >>> ... while SWing is too slow.


    Michael Rauscher schrieb:
    >> No, not the old fairy-tale again.


    Christian wrote:
    > 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
     
    Lew, Mar 18, 2007
    #8
  9. dolphin

    jupiter Guest

    "Andrew Thompson" <> wrote in message
    news:...
    > On Mar 18, 9:12 pm, "dolphin" <> wrote:
    >> Hi !Swing better than Awt?

    >
    > Define 'better'.


    My new mouse trap.
     
    jupiter, Mar 18, 2007
    #9
  10. Christian wrote:
    > Michael Rauscher schrieb:
    >> Xiaochuan Fang wrote:
    >>> dolphin 写é“:
    >>>> Hi !Swing better than Awt?How do you think?
    >>>>
    >>> ... while SWing is too slow.

    >> No, not the old fairy-tale again.
    >>

    >
    > 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);
    }
    });
    }
    }
     
    Michael Rauscher, Mar 18, 2007
    #10
  11. dolphin

    Chris Uppal Guest

    Michael Rauscher wrote:

    > > ... while SWing is too slow.

    >
    > 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
     
    Chris Uppal, Mar 18, 2007
    #11
  12. Chris Uppal wrote:
    > 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
     
    Mark Thornton, Mar 18, 2007
    #12
  13. Chris Uppal wrote:
    > Michael Rauscher wrote:
    >
    >>> ... while SWing is too slow.

    >> 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.


    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
     
    Michael Rauscher, Mar 18, 2007
    #13
  14. "Richard Maher" <> writes:

    > 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--

    --
    Web Hosting by West Virginians, for West Virginians: http://wv-www.net
    Cocoa programming in Perl: http://camelbones.sourceforge.net
     
    Sherm Pendley, Mar 19, 2007
    #14
  15. 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" <-THIS.org> wrote in message
    news:45fd951d$1$763$...
    > Michael Rauscher wrote:
    >
    > > > ... while SWing is too slow.

    > >
    > > 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
    >
    >
     
    Richard Maher, Mar 19, 2007
    #15
  16. Richard Maher wrote:
    > 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
     
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Mar 19, 2007
    #16
  17. On Mar 20, 12:26 am, Arne Vajhøj <> wrote:
    ....
    (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.
     
    Andrew Thompson, Mar 19, 2007
    #17
  18. Richard Maher wrote:
    >
    > 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.
     
    RedGrittyBrick, Mar 19, 2007
    #18
  19. Richard Maher wrote:
    > 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
     
    John W. Kennedy, Mar 19, 2007
    #19
  20. dolphin

    Christian Guest


    >
    > 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
     
    Christian, Mar 19, 2007
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Mark Bram
    Replies:
    2
    Views:
    6,028
    Robert Mark Bram
    Dec 11, 2003
  2. mkrause
    Replies:
    0
    Views:
    700
    mkrause
    May 6, 2005
  3. Peter Bencsik
    Replies:
    2
    Views:
    878
  4. Randyl
    Replies:
    2
    Views:
    376
    Roedy Green
    Jul 25, 2007
  5. Replies:
    2
    Views:
    68
    Mark H Harris
    May 13, 2014
Loading...

Share This Page