Solved

Card Layout Perfomance.

Posted on 2002-07-11
8
304 Views
Last Modified: 2010-03-31
hi,
i'm using card layout to design my interface, each card will contain a panel where this panel will include other component such as textfield, button, check box etc.

My question is, is there any performance issue if my application contains a lot of card?? should i remove the card once it is not in use, or i need to add the card dynamically...??

your suggestion is highly appreciated...

cheers...
0
Comment
Question by:pleasure
  • 3
  • 3
  • 2
8 Comments
 
LVL 5

Expert Comment

by:fontaine
ID: 7145426
No because the way it works is very simple: the layout manager simply picks up the panel you want to show and displays it, like if it was "alone". That's the whole idea of a CardLayout.
0
 
LVL 3

Expert Comment

by:yasser_helmy
ID: 7145793
The layout manager wont have any problem loading your cards. The number of cards does not affect the performance of the layout manager. You dont have to create the cards dynamically or remove them when they are not needed any more.
But, the number of cards may influence the performance in another way. The more cards you have the more memory your program uses. This reduces performance. But this is true for all variables you use in the program. For example, if you use a very large array of data the performance will be influenced.
0
 

Author Comment

by:pleasure
ID: 7148153
thanks for the response... i wish to open this question for several days in order to wait for opinion from others experts...

cheers...
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:pleasure
ID: 7153291
hi experts..
i hit problem here.. when my application load too many cards.. sometimes my system cause "Out Of Memory" error, FYI my appliction contain around 70++ cards.. it takes quite long to load the application, everytime the application started, all the cards will be loaded..

how should i fix this?? is there any other workaround i can do?? please guide...

thanks
0
 
LVL 5

Expert Comment

by:fontaine
ID: 7153645
The problem is not with the CardLayout itself. What happens is that you instantiate 70++ classes, what takes time and visibly causes the out of memory error. Despite the CardLayout displays one by one, it holds references to each card what ensures that the cards not displayed are not garbage collected. The only solution I can see is to dynamically add/remove, as far as your cards are visibly too large and too numerous to be kept in memory at once.
0
 

Author Comment

by:pleasure
ID: 7153949
hi fontaine,
can you please show me the way to remove component from card layout?

is it a good idea dynamically add and remove the component from the layout? because from my observation i think the delay of the perfomance is because i instantiate too many classes and not because too many component in the card layout.
0
 
LVL 3

Accepted Solution

by:
yasser_helmy earned 50 total points
ID: 7154243
Hi Pleasure,
The "Out of memory" error is due to the the large number of components you have. The number of instantiated classes does not affect the performance in any way. You have to create the cards when they are needed and make them available for garbage collection whenever you think they wont be needed any more.
You can create only a few cards when the application loads. When you think they are not needed, remove them from the panel, make any references to the these cards null. Create other cards when needed.
0
 
LVL 5

Expert Comment

by:fontaine
ID: 7154635
To add, you use the following CardLayout method:

addLayoutComponent(java.awt.Component, java.lang.Object)

To remove, you use the following:

removeLayoutComponent(Component comp)
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maven project error 5 56
tomcat not starting 6 45
login jsp example 24 51
Opening PDF on button click and fill new document 2 39
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question