• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About AWT!

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
See where your hand is? Not there. It's next to this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic