This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes About AWT! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About AWT!" Watch "About AWT!" New topic
Author

About AWT!

laura_zpf
Ranch Hand

Joined: Sep 14, 2000
Posts: 30
what happens if you add more buttons to GridLayout than can fit and fully display the button labels?
1)the size of the container is increased to allow the button labels to fully display.
2)the GridLayout ignores the size of the label and the labels will be truncated.
3)a compile time error indicating the buttons cannot to the preferred size.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I guess the answer is 2 coz mu understanding of GridLayout is that they ignore the preferred size of a components. Therefore, I guess 2 should be the right answer.
Somebody, please confirm this
-sampaths77
Ira Jain
Ranch Hand

Joined: Sep 06, 2000
Posts: 70
Hi!
sampaths77 ,you are right.The answer will be second because GridLayout always ignores a component's preferred size.
bye
Ira
Sagar Sharma
Ranch Hand

Joined: Aug 31, 2000
Posts: 92
if you have 4 cells ( 2 rows and 2 columns) and all cells are filled by 1 button each. Now if you try to add another button a column is added to the grid and the newly added button goes in row=2 amd column =2
the final arrangement is... (1,1) (1,2) (1,3) (2,1) (2,2)
accordingly (a) is the answer...please do check and find out if this is true.
mail me back regarding the same at sagarsagar77@usa.net
laura_zpf
Ranch Hand

Joined: Sep 14, 2000
Posts: 30
2 is the right answer. But I have done the test. it shows the right answer 1 is right. so I got comfused.
rainbow
Ranch Hand

Joined: Sep 10, 2000
Posts: 31
hi all:
I think the only correct answer is 2.just try below code to validate it.
import java.awt.*;
public class test extends Frame{
public static void main(String agrs[]){
test t = new test();
}
test(){
super("my frame");
setLayout(new GridLayout(2,2));
setSize(100,100);
add(new Button("botton1"));
add(new Button("botton1"));
add(new Button("botton1"));
add(new Button("botton1"));
add(new Button("botton1"));
setVisible(true);
}
}
you will find the Frame's size isn't increased to allow the buttons full showed.In the contrast,the Button will be truncated.
srikrish
Ranch Hand

Joined: Sep 12, 2000
Posts: 63
The buttons will be displayed accurately if we add a pack() method for the frame before the setVisible() method. But without the pack() method, I think 2 is the right answer.
Also, the API documentation says the following for GridLayout:
"When both the number of rows and the number of columns have been set to non-zero values, either by a constructor or by the setRows and setColumns methods, the number of columns specified is ignored. Instead, the number of columns is determined from the specified number or rows and the total number of components in the layout. So, for example, if three rows and two columns have been specified and nine components are added to the layout, then they will be displayed as three rows of three columns. Specifying the number of columns affects the layout only when the number of rows is set to zero."
Hope this helps.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: About AWT!
 
Similar Threads
Using GridLayout
How to make a botton smaller?
Re: Using GridLayout with Buttons
Problems positioning buttons in GridBagLayout
buttons that are not same size