This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic