Solved

Size of components in CardLayout

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

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

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.
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…
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 …
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.

912 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

24 Experts available now in Live!

Get 1:1 Help Now