• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

gridlayout

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.awt.*;
public class FlowAp extends Frame{
public static void main(String argv[]){
FlowAp fa=new FlowAp();
fa.setSize(400,300);
fa.setVisible(true);
}
FlowAp(){
setLayout(new GridLayout());
add(new Panel());
add(new Button("One"));
add(new Button("Two"));
add(new Button("Three"), "North");
add(new Button("Four"), "South");
}
}
the running result is "A panel and buttons marked One to four running from the left to right "
why?
I thought it would be " An Error at compile time indicating add is called with invalid parameters. "
add(new Button("Three"), "North"); add(new Button("Four"), "South"); Can this way be used for
GridLayout Manager?add(new Button("Three"), "North"); add(new Button("Four"), "South"); Can this way be used for gridlayout
[ June 06, 2002: Message edited by: weiliu lili ]
 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer here is,
The default layout for Frame class is BorderLayout. But you are setting to the layout to be GridLayout which will not honour for the preferred height and width. So, the panel and other buttons are added from left to right with no gap between themselves and no preferred height and width. If you resize the window, still you will see the window is divided by 5 equivalant portions with panel and buttons. This example describes the default behaviour of the GridLayout.
 
weiliu lili
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Thiru Thangavelu:
The answer here is,
The default layout for Frame class is BorderLayout. But you are setting to the layout to be GridLayout which will not honour for the preferred height and width. So, the panel and other buttons are added from left to right with no gap between themselves and no preferred height and width. If you resize the window, still you will see the window is divided by 5 equivalant portions with panel and buttons. This example describes the default behaviour of the GridLayout.


thanks for reply, what i m confused is that CAN you use add(new Button(),"North") for gridLayout?
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The add method is not defined in GridLayout, but is inherited by Frame from class java.awt.Container. My guess is that the method passes these parameters to the GridLayout manager, which simply ignores the second parameter.
 
Every plan is a little cooler if you have a blimp. And a 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