This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About AWT!

 
laura_zpf
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic