• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AWT related ( GridLayout )

 
amol re
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An AWT related question from Mughal book:
Which of these statements are true?
Select all valid answers
a. A grid made by GridLayout must have an equal number of rows and columns.
b. All components in a GridLayout will be square. Their width will be equal to their height.
c. All components in a GridLayout will have the same height.
d. All components in a GridLayout will have the same width.
e. All components within a row of a GridLayout will have the same height.
Answer: c, d, e
What i think should be the answer: b,c,d,e
Arent all components in a GridLayout square??
I have never really worked in AWT so my concepts might not be all that strong. :roll:
Amol
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never really worked in AWT so my concepts might not be all that strong.
Then you should at least try to write a piece of code which shows you that components in GridLayouts are not necessarly square. They all have the same dimensions but they are not square.
 
Neelima Rao
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The cells in the grid are equal size based on the largest component in the grid, but they dont have to be square.
 
Tosin Adedoyin
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi amol
All the cells in the GridLayout have the same height and width but this does not mean it will be a square . what this means is if the first cell has a height of 5 and width of 1 all the cells will have these same measurement i am placing a code here run and compile and see what the cells looks like i hope this helps
i did not add the event handler
class TT {


public static void main(String args[]) {
Frame t= new Frame();
t.setLayout(new GridLayout (5,1));

for (int i=0;i<10;i++)
{
t.add(new Button("Button" +i));
}



t.setVisible(true);
}
}
 
J Hreich
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
this is my first time here.
I have to say this is an excellent site with
the best quality posts.
amol,Try the following:
class Testing {
public static void main(String[] args)
{
Frame f = new Frame("hello");
f.setLayout(new GridLayout(2,2));

Panel p = new Panel();
p.add(new Button("1,1"));
f.add(p);

f.add(new Button("1,2"));
f.add(new Button("2,1"));
f.add(new Button("2,2"));

f.setSize(100, 100);
f.setVisible(true);
}
}
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir J.H. is my name
Well not here, though
Welcome to Javaranch
Please read the Javaranch Naming Policy and change your publicly displayed name to comply with our unique rule. Thank you.
 
amol re
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you should at least try to write a piece of code which shows you that components in GridLayouts are not necessarly square. They all have the same dimensions but they are not square.
yeh..you are absolutely right. i usually prefer doing that. was sitting up late last night, thats why the lethargy , i guess.
and what i stupid question it was!! the uestion reflects my unclear thinking last night. the simple explanation is that if the window to which the gridlayout is applied is itself not square, the individulal cells *CANNOT* be square!!right??
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to give you a hard time...
That's not true.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider this:

Viewed through the AppletViewer or as an embedded applet with a width of 400 pixels and a height of 300 pixels, the "window" is clearly not a square (of equal pixel numbers in width and height), and yet, using a GridLayout, the components added are displayed using an equal number of pixels vertically and horizontally.
 
WiLL Tao
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by amol re:
An AWT related question from Mughal book:
Which of these statements are true?
Select all valid answers
a. A grid made by GridLayout must have an equal number of rows and columns.
b. All components in a GridLayout will be square. Their width will be equal to their height.
Amol

i think the answer a equal answer b,
if their width be equal to their height,a grid made by GridLayout must have an equal number of rows and columns.
so they both wrong
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by WiLL Tao:
if their width be equal to their height,a grid made by GridLayout must have an equal number of rows and columns.

And I'll give you a hard time also...
See above code snippet which dispells your assumption.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic