• 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

JScrollPane performance problem

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

I am writing a small Swing application that builds some JPane "windows" on the main screen before displaying anything, and when user pushes the pane selection buttons, I simply set the choosen one visible.

My problem is, that one of the panes contains a JTable inside a JScrollPane.
When I call myPanel.setVisible(true); for the first time, the whole GUI hangs for approx. 3 seconds, and the HDD led shows that some large amount of something is being read. I use JRE Standard Edition build 1.5.0_04-b05.
When displaying only the table, not wrapped with a JScrollPane, no such delay occurs.

The code fragment is:


and I display them as

or

Does anybody know, what's going on, and how to overcome this delay?
I've read several "swing performance tips" pages but could not find the answer for this...

Thanks in advance,
Brian

Update: I also tried to analyze code with the help of JProfiler. It shows that JScrollPane requires only 18ms of CPU time...

[ October 07, 2005: Message edited by: Brian Twodoor ]
[ October 07, 2005: Message edited by: Brian Twodoor ]
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried your code snippets and they work okay. It is generally not a good idea to be calling
'setVisible' on components in a top–level container to control their visibility. You
can add/remove components (followed by a call to validate/revalidate to the parent) or
use a CardLayout or, in some cases, a JTabbedPane.

edit: adjust width
[ October 07, 2005: Message edited by: Craig Wood ]
 
Gergo Csaki
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Craig Wood:
It is generally not a good idea to be calling
'setVisible' on components in a top–level container to control their visibility. You
can add/remove components (followed by a call to validate/revalidate to the parent) or
use a CardLayout or, in some cases, a JTabbedPane.

edit: adjust width
[ October 07, 2005: Message edited by: Craig Wood ]


First of all, thanks for the quick reply.
I thought that putting all of the controls to my forms while showing a splash screen would be a good idea, because the JRE would have time to arrange everything as it wishes, and setting each panel's visibility would take no time at all, as the components are already on their places. Why is calling setVisible() on their containers a wrong idea? I am not sure that JTabbedPane is good for me, and I do not know CardLayout at all, I'll play with them.

What does "edit: adjust width" mean?
Regards,
Brian
 
Gergo Csaki
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, CardLayout is _exactly_ what I wanted...
As it's 1.33 AM here, I won't rebuild the app now, but I'll try using my JScrollPane this way tomorrow

Thanks,
Brian
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is calling setVisible() on their containers a wrong idea?
It has to do with how the awt puts components together. The java tutorial has information
about this on the page Using Layout Managers.

What does "edit: adjust width" mean?
When I posted my reply I forgot that the thread was stretched (wide) and saw that the text
in my reply went offscreen. So I did an edit to break it up so it would be readable without
scrolling left and right.
 
Gergo Csaki
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, after rebuilding the gui displaying JScrollPane is still slow, takes about 2 seconds, while all other panes appear immediately.

I'm writing this app on Linux, now I'll try running it on Windows...
reply
    Bookmark Topic Watch Topic
  • New Topic