Solved

Size of components in CardLayout

Posted on 1997-05-12
3
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

635 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