• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Any performance tips ?

 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I've hit a point in my app where when I first call .validate() when loading a new panel (it is fairly complex), it takes up to 5 seconds to load.. There must be something I can do to get over this and was wondering if anyone had any ideas, if you are interested then my App flows like this..

A quite simple frame is initially created and displayed to user, this contains a button with 4 buttons, a BIG panel and a menu bar and thats it for now. the button bar is on left, menu at top and the Panel taking everything else up..

When the user clicks a button, an appropriate panel is then called and 'loaded into' the big empty space where the panel is. All this is in a function called Show() which is as follows...

private void show(Component component) {
java.awt.GridBagConstraints gridBagConstraints;
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;

Main.removeAll();
Main.add(component,gridBagConstraints);
this.validate();
}

when a button is clicked, depending on the button I call the show command like this...

show(new divelog.forms.ProfilePanel());

The panel that gets loaded that I have a problem with containt 3 panels in a tabpanel. each one of those has a table, and maybe 10 textfields per panel.

So not really all that much complexity I dont think, the instantiation of the panel doesnt take long, so setting up the listeners I have seems ok its just the moment the .validate() line is executed there is the 5/6 second delay.

Anyone any ideas ? I was thinking Ok I'll create the instances of the panels in a seperate thread, but as I said the creation doesnt really take anytime at all.

Thanks in advance.
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you need to call this.validate(). What happens if you don�t call it?
 
Ranch Hand
Posts: 227
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Don rightly asked, its important to know the significance and purpose of validate() method here. We should always refrain from assigning possibly lengthy tasks to GUI (Event dispatch) thread, even if the result of the operation is going to affect the GUI.

Instead, we must use multi-threading APIs like SUN's SwingWorker or SourceForge's FoxTrot. I suggest you go through these for reference. Even if they don't fit the bill perfectly, I'm sure you'd get an idea about how to go about your problem.
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Calling validate from the event thread is the right thing to do after changing the contents of an AWT container that's on screen already (revalidate() is the right method to use for JComponents). Five seconds to do layout on a component is definately unusual. I'd guess something's fishy in ProfilePane. Do you still have performance problems if you pass some other component to show(), like perhaps a button?
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey all

Thanks for your replys. I did some profiling with a trial of JProfiler, noticing that the problem was specifically on the .validate() call. Initially thought this just must be standard Swing behaviour but someone suggested I see why validate() is taking the time. I didnt realise I could do that but then realised that the profiler could be set to ignore certain calls, like JAVA.*.

Once I could see the java.* calls I could see that the bloody thing was spending most of its time loading a font!!! Tahome to be exact, I thought a different font would improve my presentation a bit on the labels, I like Tahome more than MS Sans Serif, but I didnt consider it may cause an extra 5 seconds of loading time. once i set them back to default fonts it speeded up dramatically. !

Another lesson learnt I suppose....

Thanks all for replys anyway
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic