Solved

Card Layout Perfomance.

Posted on 2002-07-11
8
307 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
varialbe initialization 11 37
JAVA API design with micro service cloud in mind 1 41
maven disable workspace resolution 1 15
ejb entity bean example issue 2 16
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

792 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