Solved

Card Layout Perfomance.

Posted on 2002-07-11
8
298 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 5

Expert Comment

by:fontaine
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.

772 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

16 Experts available now in Live!

Get 1:1 Help Now