Why Swing

I need to define a clear set of guidelines for when it is appropriate to use Swing over a Broswer based implementation. My experience tells me the following:
Using Swing launched with Web Start:
UI has richer components
More powerful client side processing with fewer trips to the server
Use of threads
Asynchronous processing
Large amounts of client side data
Using Browser based:
UI limited to HTML (unless you use something like Flash, but then there is a performance issue)
Synchronous processing requiring a trip to the server on each action
No threading
Data is more form based
Other thoughts?

Java WebStart is very good for distributing an
application.Good point. The only deployment problem WebStart has, at least as far as I know, is that it still requires the user to have a JRE installed. Unfortunately, there are still audiences that have trouble doing that on their own. And that's not considering some of the things I've read about problems with multiple JRE/JDK installations.
The Ajax technology is a architectural nightmare;
nice results, but ugliness under the hood.Could be, I've little experience with it. I was just pointing out the fact that a browser based client does not require syncrhonous communications.
If I look at the results my browser gets from e.g., gmail, I'm inclined to agree that a lot of "fancy" technologies for browser-based clients quickly get messy

Similar Messages

  • Why Swing instead of...

    This is a quote from the Java Tutorial:
    Note: We strongly recommend that instead of using the AWT components shown on this page, you
    use Swing components instead.
    Then why talk about both? Both need to be understood depending on the job?

    You need to understand AWT when using Swing if for no other reason that Swing is built on top of AWT.
    Col

  • Why is swing so slow ? :(

    Why java don't use native code for creating UI ?
    Any application, writen in swing is SLOW ...
    compared with .NET for example...
    even well tuned examples a too slow for using.
    I like java, but this $#%ing swing kills all GUI applications.

    The sad truth is that Swing has got such a bad wrap
    that many flock to SWT thinking its the holy grail of
    Java UI development because Swing is so bad. Nothing
    could be further than the truth. SWT is great in many
    respects, but Swing is better in many respects as
    well. If done right, Swing beats SWT in most cases.
    With JDK 1.4.2 improvements are even better, and on
    Mac OS X, Apple works with Sun to build their own
    optimized JVM, so Swing is pretty darn fast, near
    native performance on Mac OS X.
    I wish there was a faster way to get the truth about
    Swing out there. One problem, a lot of developers are
    not the types to accept that they wrote crappy code
    and thus their slow Swing performance is a direct
    result of their bad coding. It's a shame really.
    Accepting that you wrote some crap code only helps you
    get better...well, unless you really do stink at
    programming, then a career change may be in order ;)Well, this about wraps up my feelings about SWT and Swing.
    The problem with many programmers is: they don't like to read.
    Unfortunately Swing is too complex to write a decent program without a concerted effort in reading at a minimum the online tutorials, but to become professional you need a good Swing book.
    Once you get the hang of Swing it is actually better than Visual Basic or MS Access. I have written code generators for MS Access and Ms SQL Server applications. But I like Swing better for many reasons. For example a VB GUI is static, while with Swing you can create a form on the fly. I can go on for a couple of pages of why Swing is so cool, but I simple want to state that statements about Swing should be based on facts, not on some hype.
    Of course Swing can be made easier. That is why Sun is building a product like Rave.
    Swing is here to stay. Within just a couple of years more and more VB programmers will be coding Swing.
    This is good for Swing for the IT industry as a whole, becuase it will mean an explosion in quality products for the consumer market.

  • Help with problems in Swing

    Hi, I am trying to develop a simple applet where a user can click on the screen to add jbuttons at the location of the mouse click. I have written an overly complex set of code that tries to achieve this goal, and in the end I have come close. My applet allows the user to input a certain number, and then click that many times on screen to create more jbuttons. The problem is that whenever the user clicks on screen a jbutton is created, but it only appears once the mouse has moved over it. I find this pretty weird, but basically when the user clicks, a jbutton is created within the program, but it is only "drawn" to the screen when the mouse moves directly over it.
    www.geocities.com/nickv360
    Can anyone explain to me why this is happening?
    http://www.geocities.com/nickv360/Source/AirlineModel.java
    http://www.geocities.com/nickv360/Source/City.java
    http://www.geocities.com/nickv360/Source/DrawingCanvas.java
    These are the source files if that helps at all. Addtinonally, the reset button doesn't work. The way the applet is supposed to be set up is to have an array of cities (JButtons) stored in DrawingCanvas. The drawing Canvas then accesses that cities[] array and adds each city[i] to the map. If there are no cities in the cities[] array, then no cities will be added. So, in order to successfully reset the map, here is what I do:
    cities = new City[numCities];
    removeAll();
    index = 0;
    repaint();
    I change the cities[] array to a new array of cities. I use the removeAll() method to take away all the JButtons that are currently on the map, I reset the index counter, and I repaint. Unfortunately this doesn't work.
    Does anyone know why Swing won't paint my buttons until the mouse moves over them, and why the reset method I've written doesn't work? Thanks in advance to anyone who can help.

    Just wanted to let people know that I found the answer:
    As for the other problem, I think it has to do with you having overridden paint. Normally, when you call repaint on a container, it will automatically call repaint on all the components that it contains. I'm fairly certain that if you don't manually call super.paint(g); in your paint method, it won't do it for you.
    Calling super.paint(g) makes the all of the bugs in the code disappear.
    Thanks.

  • Does Swing has anything to do with Hardware

    I have a laptop that freezes any time i load any DirectX games on it especially ones that make use of hardware acceleration, i guess its the laptop harware fault anyway but Suddenly i realize that the same freezing behavior takes place anytime i am running any swing related code only. Any time a swing application loads up, it just freezes just as the DirectX games freezes it. Thats why i want to know if the swing API uses directX somehow
    In anger i wiped out windows and put linux. I got no such problems

    Just tell me why swing could be possibly be freezing
    my system in windows and in linux its notYou want to know why windows is crashing, and linux isn't... Where have you been for the last 20 years? (yeah, I know windows has only been around since 85, but they copyright claims it was around for a year before the mac was released... Isn't it cool they way you can re-write history)
    Who controls the past, controls the future.
    Who controls the present, controls the past.
    ---- 1984 by George Orwell

  • Using null Layout - Problems

    Hullo - I've written a little app that, because of the nature of what it does, prettymuch requires the use of null layout. It works well enough, but there are a few points where it does strange things that I don't understand. I haven't been able to find any good docs anywhere for how exactly layout/rendering works. The Swing tutorial, for example, almost completely ignores the topic.
    Basically, I set the layout to null, add my components, use setBounds...but then nothing happens. In order for anything to be visible, I have to call pack() before I call show(). What is pack? What does it do? How can Sun's null layout examples work even though most of them don't use it?
    Second, if I create JFrame of a certain size, and add a component that goes off the bottom of the JFrame (on purpose), then expand the size of the JFrame to reveal the bottom part of that component, it doesn't paint - there's just a grey area. No amount of repaint() pack() or anything will cause it to show. The only way I've found to do it is to make the JFrame larger to begin with, add the component so that it's visible, then resize to the smaller size, which is kind of ugly and clunky.
    I basically do not understand why Swing is doing the things it does; why it paints sometimes and not other times, where it paints, when it paints, where it shows objects, how it packs them, etc. I would be very grateful if someone could englighten me!

    Hullo - I've written a little app that, because of the
    nature of what it does, prettymuch requires the use of
    null layout. It works well enough, but there are a
    few points where it does strange things that I don't
    understand. I haven't been able to find any good docs
    anywhere for how exactly layout/rendering works. The
    Swing tutorial, for example, almost completely ignores
    the topic.
    Basically, I set the layout to null, add my
    components, use setBounds...but then nothing happens.
    In order for anything to be visible, I have to call
    pack() before I call show(). What is pack? What
    does it do? How can Sun's null layout examples work
    even though most of them don't use it?
    Second, if I create JFrame of a certain size, and add
    a component that goes off the bottom of the JFrame (on
    purpose), then expand the size of the JFrame to reveal
    the bottom part of that component, it doesn't paint -
    there's just a grey area. No amount of repaint()
    pack() or anything will cause it to show. The only
    way I've found to do it is to make the JFrame larger
    to begin with, add the component so that it's visible,
    then resize to the smaller size, which is kind of ugly
    and clunky.
    I basically do not understand why Swing is doing the
    things it does; why it paints sometimes and not other
    times, where it paints, when it paints, where it shows
    objects, how it packs them, etc. I would be very
    grateful if someone could englighten me!Okay, I think you should call setVisible(true); instead of pack then show. Pack basically organizes the components so they take up the least amount of room, and then it shrinks the frame to as small as it will go without hiding any components. It think if you call revalidate() instead of repaint(), should solve your problem.
    The other thing to do, is (hehe) make your own components

  • To change the width of a Table Column

    Hai Developers..................
    I have problem with the Table Column Width.
    When am on search state.
    The search results are showing in a table.
    At that time i want to change the width of the each column with respect to the column content.
    Like the jsp table.......
    Pls replay with example......
    Thanks.

    And that is why Swing related questions should be posted in the Swing forum so we don't spend time guessing what you are talking about.
    Darn, the [Table Column Adjuster|http://www.camick.com/java/blog.html?name=table-column-adjuster] didn't show up in that Google search.

  • What does it mean to be "thread safe"?

    What does it mean to be "thread safe"?
    I am working with a team on a project here at work. Someone here suggested that we build all of our screens during the initialization of the application to save time later. During the use of the application, the screens would then be made visible or invisible.
    One of the objections to that idea was that the swing components (many of which we use) are not thread safe. Can anyone tell me what the relevance of that is?
    Thanks

    To understand why Swing is not thread safe you have to understand a little bit of history, and a little bit of how swing actually works. The history(short version) is that it is nearly impossible to make a GUI toolkit thread safe. X is thread safe(well, sorta) and it's a really big mess. So to keep things simple(and fast) Swing was developed with an event model. The swing components themselves are not thread safe, but if you always change them with an event on the event queue, you will never have a problem. Basically, there is a Thread always running with any GUI program. It's called the awt event handler. When ever an event happens, it goes on an event queue and the event handler picks them off one by one and tells the correct components about it. If you have code that you want to manipulate swing components, and you are not ON the awt thread(inside a listener trail) you must use this code.
    SwingUtilities.invokeLater( new Runnable() {
      public void run() {
        // code to manipulate swing component here
    });This method puts the defined runnable object on the event queue for the awt thread to deal with. This way changes to the components happen in order, in a thread safe way.

  • X11 Pipeline: Extreme Thrashing

    I have a graphics intensive application that I am working on, and I am getting severe thrashing while running in X. Results are excellent from an e-machine running Windows Vista.
    Here's the basic idea of the program. It uses AWT (no Swing is ever referenced). There is a collection of "sprites" which were created from GraphicsDevice.createCompatibleImage() to give them the best chance at acceleration. Then there is a backbuffer, to which the program draws. It attempts to deliver higher framerates by only updating portions of the screen which are changing. Originally, this backbuffer was also created with GraphicsDevice.createCompatibleImage(), however this leads to the thrashing I mentioned earlier.
    After reading through:
    [Troubleshooting Guide for Java SE 6 Desktop Technologies|http://java.sun.com/javase/6/webnotes/trouble/TSG-Desktop/html/toc.html]
    I managed to isolate the problem to X11 offscreen pixmaps, and running with the flag -Dsun.java2d.pmoffscreen=false removes the thrashing.
    The problem I have here is that I am now confused. It seems to me that I want my sprites accelerated, but shouldn't my backbuffer also be accelerated? I'm not using antialiasing, nor alpha compositing, nor translations. I do make heavy use of setting the clip on the graphics object. Is that where my problem resides? Am I confused on the meaning of alpha compositing... does that include 1-bit transparency?
    Quote from the above referenced document:
    "The use of pixmaps typically results in better performance. However, in certain cases, the opposite is true. Such cases typically involve the use of operations which cannot be performed using the X protocol, such as antialiasing, alpha compositing, and transforms that are more complex than simple translation transforms.
    For these operations the X11 pipeline must do the rendering using the built-in software renderer. In most cases this includes reading the contents of the pixmap to a system memory (over the network in the case of remote X server), performing the rendering, and then sending the pixels back to the pixmap. Such operations could result in extremely poor performance, especially if the X server is remote."
    Could someone enlighten me here? Why are my accelerated surfaces being copied back into system memory when all I am doing is drawing accelerated surfaces onto accelerated surfaces using drawImage() and setClip().

    You're totally right. I was preparing a code example, during which I discovered my mistake.
    I'm still curious as to why Swing is causing a problem with off screen pixmaps in X. I've seen this problem before but I was never concerned with rapid updating of the screen so I never investigated. I think it must be Swing's backbuffer causing it, but is this a problem with the Java2D X11 pipeline, or maybe a bug somewhere else in my OS?
    Here is a code example which produces the problem, running it with sun.java2d.pmoffscreen=false runs fine, but without it, X begins hogging CPU time and starves Java out resulting in pauses in execution.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    class SwingFail implements ActionListener {
      private static JFrame frame;
      class RefreshPanel extends JPanel {
        public RefreshPanel() {
          setPreferredSize(new Dimension(512, 512));
        public void paintComponent(Graphics g) {
          g.setColor(Color.black);
          g.fillRect(0, 0, 512, 512);
          g.setColor(Color.white);
          g.drawString(new Date().toString(), 25, 250);
      public SwingFail() {
        frame = new JFrame("Rapid Refresh");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel = (JPanel) frame.getContentPane();
        panel.add(new RefreshPanel());
        frame.pack();
        frame.setVisible(true);
      public void actionPerformed(ActionEvent e) {
        frame.repaint();
      public static void main(String[] args) {
        SwingFail sf = new SwingFail();
        javax.swing.Timer t = new javax.swing.Timer(1, sf);
        t.setCoalesce(false);
        t.start();
    }PS This is with Java 5, and the underlying OS is in bad need of an update so I wouldn't be surprised if this issue has long since been resolved, but I'd still love to hear from someone else running X11 if this works well or not. Of course hardware performance may be a factor, but the difference in CPU time should still be evident between turning offscreen pixmaps on or off.
    Edited by: DecadeOfJava on Jun 19, 2010 6:34 AM

  • Multiple paintCell calls

    Hi!
    I have a performance problem in an application using a large JTable. During debugging I noticed that paintCell() for each field of the table is called multiple times, and that each row is repainted as a whole even though only one cell has changed in that row.
    Does anyone know why Swing seems to want to repaint each cell multiple times? Is there a way to stop this, and is there a way to repaint only certain columns in a row?
    Regards,
    Ziph

    I have a performance problem in an application using a large JTable.The size of the table shouldn't matter. As you said only the entire row is repainted. So if it that that long to repaint 10 cells, then there is something wrong with your renderer.
    Is there a way to stop this, and is there a way to repaint only certain columns in a row?I'm sure there is but you would need to rewrite the table UI.

  • Focus of a JTextField & font size.

    The program has a FlowLayout in which 2 JTextFields are added by means of
    add(new JScrollPane(verbInstructions));
    add(new JScrollPane(verbTextBox));
    How can the focus be set to verbTextBox elsewhere in the program?
    Also how can the size of the text moved to a JTextField be in a smaller font than the default?
    Thanks for your help.
    Edited by: zscipio on Sep 30, 2009 7:41 AM

    camickr wrote:
    grabFocus worked. Yes, but if you read the API you will find:
    This method is intended for use by focus implementations. Client code should not use this method; instead, it should use requestFocusInWindow().
    Ah! Sorry, OP. Then again...
    That is why Swing related questions should be posted in the Swing forum.A fair point!
    What's the reasoning behind this, out of interest?

  • Menu, Button, Menuitem backgroundcolor

    is there any way to change the menu , button , menuItem background color,
    i know there is hastable for maintaing ui component color. and one can get the
    that defaults value using UIManager.getDefaults(). which returns a hastable . and you can set the key with corresponding value for some component.
    UIManager.getDefaults().put("win.menu.backgroundColor",Color.RED);
    but that doesnt work.
    but the following line works
    UIManager.put("TableHeader.background", Color.RED);
    but the following line doesnt work.
    UIManager.put("ScrollBar.background", Color.RED);
    i dont why swing team exposed the api , and that api doesnt works. :)

    While it would be nice if we could expect all LookAndFeel implementations to use the same keys in the UIDefaults table, and while most implementations I've seen do make every honest effort to do so, it's not guaranteed. There's no reason why an LAF couldn't use a completely arbitrary set of keys, as long as all its associated UIs were geared for it. So... when you're trying to make changes to the UIDefaults table, it's always a good idea to check the LAF class. For example, let's pretend like we're working with the Metal look and feel (javax.swing.plaf.metal.MetalLookAndFeel class). It subclasses the javax.swing.plaf.basic.BasicLookAndFeel class, so remember to look up the heirarchy.
    And we'll see that the key for the background color of a JMenuItem is "MenuItem.background", a JButton is "Button.background", and JMenu is "Menu.background". Those are the keys you set in the UIManager.
    Personally, I prefer putting in a javax.swing.plaf.ColorUIResource instead of a straight java.awt.Color. But that's me.
    As for why "ScrollBar.background" isn't working for you, well, it seems like it should, but you might double-check the ScrollBarUI for the LAF you're using and see if maybe it's not looking somewhere else.

  • Uploading large files using nio in http client

    Hi,
    I'm developing a multithreaded Swing client which needs to be capable of uploading and downloading large ( 100mb ) files to servlets via http.
    Downloading has presented no problem, but writing to the OutputStream of a URLConnection, whilst fine for small files, gave me 'out of memory' errors on large ones. ( As I understand it, the whole stream is buffered before sending and it just runs out of room.)
    So I replaced the URLConnection with a SocketChannel, and after writing the http header, used a loop to write chunks of data from a FileChannel.
    I needed to monitor any incoming data to truncate the upload if the servlet gives a premature response indicating an error condition, so I set the SocketChannel to non-blocking and put a read into the loop.
    Immediately I got a bunch of Swing exceptions and the frame was unable to render itself, I guess due to thread starvation problems.
    I currently have this clunky code that seems to work ok:
    int percent=0;
    long total = 0L;
    long chunk = 1024*8;
    while(total<length ){
    chunk = ((length-total)<chunk)?length-total:chunk;
    long ii= fc.transferTo(total,chunk,socketChannel);
    total+=ii;
    yield();
    socketChannel.configureBlocking(false);
    if(socketChannel.read(buffer)>0 )break;
    socketChannel.configureBlocking(true);
    What I can't figure out is why Swing objects if I permanently set the SocketChannel to non-blocking rather than just whilst I read it, and why I get the following exception from a polling thread that runs concurrently:
    'No buffer space available (maximum connections reached?)'
    Anyone got any ideas or a better way to do it?
    Chris

    I assume that the OutputStream obtained fromURLConnection is internally buffered and URLConnection
    waits until the whole stream has been input before
    inserting the initial Content-length header. Only when
    it knows the complete length is the content sent. Hmm, this is quite unfortunate. Especially since it is not necessary: HTTP allows the data stream close to serve as the end-of-data marker (Content-Length: is an optional header, in its absence the receiver simply reads all of the data until the sender closes the stream).
    Has anyone else had experience of sending large
    (100mb) files through Java http clients on small
    pc's?I've sent large-ish (~1-10Mb) payloads via URLConnection but not as large as yours. Interesting issue to figure out... I am out of ideas for the moment.

  • Iconfied Java Program as daemon at right bottom in win platform

    In My java application, I want make the JFrame not visible when it is iconfied, but still can been shown by click on the right of the task bar.
    In a word, I just want it be hidden in window platform
    So what should I do?
    Thanks in advanced

    I think I just read that SWT is able to do so.
    With just swing or awt, you can't.
    -T-
    P.S.: Yes there is a reason why swing and awt don't support it. Do a search, there have been very elaborate threads on this topic.

  • Cancel cell moving after type enter in jtable

    Hello !
    Im working with a swing jtable, I want to do something at event jTableKeyPressed, with Enter, It's Ok. But after that I want to cancel the Enter movment to the next row.
    Can anybody tell me how to do that ?

    And that is why Swing related questions should be posted in the Swing forum, because Swing developers do know the technique.agree
    Why? Again we don't know the OPs full requirement. All the OP said was he didn't want it to go to the next row. So I would say the solution is working correctly. It doesn't go to the next row.also agree.
    I was just thinking from users perspective. If I were using such application, after editing cell and hitting ENTER I would expect the cell to loose focus so I could move to next one. As you mentioned in another thread - list all drawbacks of your solution so others can make decision weather to use it or not. Just listened to your advice.

Maybe you are looking for

  • ZEN 2.0 & Creative MediaSource Mana

    My Zen 2.0 have worked fine with Creative MediaSource Manager. But after reinstalling my Win XP (SP2) and all programs, drivers etc, it will not recognise my player anymore. I also installed the old program PLay Center which came with the player and

  • Bash script read input and feh

    I was trying to make a quick script to organize some pictures using feh to display the picture in question and then using bash to read a character from the keyboard and move to a folder based on that letter. Problem is it opens every image in the fol

  • Change selected row when press tab

    Hi I use JDev11.1 with ADF, i have grid in my jsf page, this grid are updatable, i need when i press tab and go to next record set selected row that cursor on it, how can i do that? Thanks

  • Clear text if validation fails

    I have a date field for which i have set a particular pattern("DD/MM/YYYY"). I want to clear off  the entered value if user types in the value in wrong format. let me know how to achive this. thanks

  • When I woke up.  The day after!!!

    I didn't think, Ok, what have I done! Yep its day two and I freakin love everything about this phone. No regretful feeling at all, like I did with my X, and thinking I could just grow to like it. I wish VZW would have done a better job so more custom