Re: grid bag layout problem
gk wrote:
Frame f = new Frame("Question 3");
f.setLayout(new GridLayout(2,3));
Note that GridLayout and GridBagLayout are separate
and distinct layouts (and classes).
for(int i=0;i<(int)Math.round(6.51);i++){
Perhaps there is a higher purpose to the statement ..
i<(int)Math.round(6.51)
...but I will point out that it is easier to write instead..
i<7
f.add(new Button(""+(i+1)));
}
f.pack();
f.validate();
f.setVisible(true);
the output is not understable.
the output button is
1 2 3 4
5 6 7
That equeste to your code, yes.
Question :
why the output is like this ?
The loop goes from 0-6 inclusive - a total of
seven numbers.
see, we have GridLayout(2,3) , this means its a 2x3 grid .....right ?
Yes. But once you feed it more than 6 components, ..
"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."
Now tell me, where is the mistake in my solution......why the real
solution does not match with my answer ?
The loop runs 7 times.
Andrew T.