• 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

layout

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi....I have a question about Gridlayout.
Suppose there is a container with the Gridlayout(2,2) and i have about 8 components to add to it....how will this get accomplished???...i read somewhere that the more columns will be created to accomodate this but no rows....
How??? if so in what way are the remaining components added to the container....???
ie will the remaining components get added row first (horizontally) or do the columns get filled out first...
HELP.......
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try the beginners area next time...
please download the jdk documenatation from sun...
the constructor for the GridLayout is GridLayout(nRow, nCol);
so a Gridlayout(2,2) will only display the 1st 4 of 8 components.
hope this helps....
Monty
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Grid layout arranges row by row. Original grid layout has grid(2,2). When you start adding additional element, it creates extra columns and re-arranges the items in the grid.
So when you add 5 th element, an extra column is created and so on for each additional column if there is no space.
Hope this helps.
Ramnath
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your case, two more columns will be added to the grid. So the components will be arranged in two rows and four columns.
when you specify a number of rows and columns as greater than one(i.e not zero), and add more components to the container than the grid will accomodate, the number of columns will be increased appropriately.
when can specify either the number of rows or the number of columns as zero(but not both). If you specify the number of rows as zero, the layout manager will provide as many rows in the grid as are necessary to accommodate the number of components you add to the container. Similarly, setting the number of columns as zero indicates an arbitrary number of columns.
hope this helps you.---
 
Anonymous
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 stand corrected... Thank-you
Code to prove your point:
import java.awt.*;
public class test2 extends Frame{
public static void main(String argv[]){
test2 cl = new test2();
}
test2(){
Panel p = new Panel();
p.setBackground(Color.pink);
p.add(new Button("One"));
p.add(new Button("Two"));
p.add(new Button("Three"));
p.add(new Button("Four"));
p.add(new Button("Five"));
p.add(new Button("Six"));
add("South",p); add(p);
add(new Button("One"));
add(new Button("Two"));
add(new Button("Three"));
add(new Button("Four"));
add(new Button("Five"));
add(new Button("Six"));
// setLayout(new FlowLayout());
// setLayout(new BorderLayout());
// setLayout(new GridLayout());
setLayout(new GridLayout(2,2));
setSize(300,300);
setVisible(true);
}
}
Time to go home, enjoy the rest of the day
Monty
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But REMEMBER:
GridLayout managers behave very strangely when you have them manage very few or very many components. Try the followings by uncommenting proper lines to observe some interesting things:
import java.awt.*;
public class Test extends Frame{
Test(){
setLayout(new GridLayout(2,2));
//setLayout(new GridLayout(-2,-2));
//setLayout(new GridLayout(12,-4));
//setLayout(new GridLayout(2,298));
//setLayout(new GridLayout('2','2'));
//setLayout(new GridLayout('?',2));
//setLayout(new GridLayout(-0,2));
add(new Button("1"));
add(new Button("2"));
add(new Button("3"));
add(new Button("4"));
add(new Button("1234MID6789"));
setSize(300,300);
setVisible(true);
}
public static void main(String args[]){
Test fm = new Test();
}
}
these should give you more insight or confuse you properly
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic