Solved

Card Layout Perfomance.

Posted on 2002-07-11
8
301 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now