This discussion is archived
6 Replies Latest reply: Nov 6, 2012 7:30 AM by 972823 RSS

How to improve the Performance of Swing Components

user8557977 Newbie
Currently Being Moderated
Hi


I have developed a GUI Framework with Swing components. I observed that when number of components are more, the GUI is slow. Could anybody suggest me the ways to improve the performance of Swing Components



Thanks
  • 1. Re: How to improve the Performance of Swing Components
    814246 Newbie
    Currently Being Moderated
    use profiler to see the performance of your UI. check for object creation and garbage collection.
    without code its hard to say issue with swing component or with your code.
  • 2. Re: How to improve the Performance of Swing Components
    EJP Guru
    Currently Being Moderated
    I have always found it blindingly fast actually, except in cases where I have done something wrong, such as long-running operations in the event thread, or Swing operations from outside the event thread.
  • 3. Re: How to improve the Performance of Swing Components
    gimbal2 Guru
    Currently Being Moderated
    EJP wrote:
    I have always found it blindingly fast actually, except in cases where I have done something wrong, such as long-running operations in the event thread, or Swing operations from outside the event thread.
    Same here. I've created complex gui's composed through multi-level nested panels and layout managers with an animated look & feel (substance); never saw so much as a glitch.

    So yeah, if its slow your computer is either cruddy or you're doing something horribly wrong. Of course impossible to say what that 'something' is.
  • 4. Re: How to improve the Performance of Swing Components
    945083 Newbie
    Currently Being Moderated
    Hi There - I haven't found issues so far with the speed of the GUI building, it seems fast when compared with .NET applications

    Are you doing any database querying on form load? This can slow down the loading of the GUI, I use persistence in an application and before the GUI is shown the persistence unit logs in to the database and registers itself - it does take 2/3 seconds to register and complete whatever it does before the form builds and shows

    Also check if you are loading/using any network based files on form load, this can also slow down the building considerably as well. Apart from that it's hard to say where your issue may lie apart from removing controls and checking build speed until you find the one that's slowing it down (not a good approach though) I sometimes had to load csv files from a network drive and if the file server is slow or LAN speed isn't great this can also cause a delay, hope you find it.....
  • 5. Re: How to improve the Performance of Swing Components
    929204 Newbie
    Currently Being Moderated
    I've heard that the text components that handle multiple styles and forms of content can get clunky when the document is (very?) large. I haven't bothered to test this myself.

    If there is some type of processing that you could do on its own thread, you might want to look into swing worker threads.
  • 6. Re: How to improve the Performance of Swing Components
    972823 Newbie
    Currently Being Moderated
    You must be aware that Swing components are not thread safe and hence it is required not to use perform Swing (UI) related task from any thread except EDT(Event Dispatch Thread) and not to perform any background operation within the EDT. I have seen this to be the major reasons for performance hit. Make sure to start a new thread if you need to perform a background activity in response to a UI action. For example on click of a button. Similarly make sure to use invokeLater or invokeAndWait methods from SwingUtilities when you want to do a UI update from a thread of you application.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points