Solved

Size of components in CardLayout

Posted on 1997-05-12
3
382 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 84
hibernate example for saving data 19 37
ejb on wildfly 5 19
Java Restore security prompts not working 10 5
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

813 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