Solved

Size of components in CardLayout

Posted on 1997-05-12
3
380 Views
Last Modified: 2006-11-17
I have several containers held by a CardLayout. Each of those contains a component the layout of which depends on its size. I have two problems:

1.
All containers except the one initially showed claims their width is 0, even when they are switched to later on, that is,  showed in the CardLayout. Therefore the component spoken of doesn’t lay out itself properly in those containers.

2.
I don’t really know which method to overload to make it tell the component to reorganize its layout when the main container (the entire applet in my case) is resized. Is it resize()? Validate()?

Can anyone help me out?
0
Comment
Question by:d95-mae
3 Comments
 
LVL 6

Expert Comment

by:jpk041897
ID: 1220388
Not an answer, just an alternative.

I used to encounter the kind of problems you described (and others) all over the place.

You might want to look at LAVA at:

http://www.cs.nott.ac.uk/~dsp/lava/

It is a GUI designer (that needs JDK 1.1 to run) that generates AWT layout code (compatible with both 1.0 and 1.1). Amongst its options, it allows you to define your components as percentages of a larger component.

Solves all kinds of headaches.

Now regarding your specific problem, could you post your init method, or wherever it is that you are defining your GUI to help in solbving your problem?

My initial though is that you are using fixed values instead of percentages of screen, which can cause the behaviour you are describing.
0
 
LVL 1

Expert Comment

by:mlimotte
ID: 1220389
I don't know if this will help, but here it is.

I believe the width and size are determined after the component is added.  So, if you need to test the width and size you might want to override the addNotify() method and do it there.

0
 

Accepted Solution

by:
stefanoq earned 50 total points
ID: 1220390
Use validate not addNotify.  Any time you make a change to a Component on a container whose geometry is managed you must call the verify method to cause the layout managers to recompute its display.  I have found that it is safest to call verify on the component itself;  containing components with layout managers are notified.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

747 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

12 Experts available now in Live!

Get 1:1 Help Now