This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Grid Layout

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is a question on gridlayout.
There is a gridlayout (2,2). all the four grids are filled up. if i add a new componenent which row will/column it occupy?
Joe
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you add a new component the "row" remains same , say 2 in u'r case. Whereas "column" increases depending on how many components you add.

eg:
setLayout(new GridLayout(2,2));
add(new Button("1"));
add(new Button("2"));
add(new Button("3"));
add(new Button("4"));
add(new Button("5"));

The display outputs 2 rows and 3 columns ie., 3 buttons in 1st row and 2 buttons in the 2nd row.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering about the same thing myself one day so I wrote a little Java program to test it. Just enter the rows and columns on the command line followed by the number of buttons you want.
Hope this helps, Regards, Joe
import java.awt.*;
import java.awt.event.*;
class DynaGrid extends Frame {
DynaGrid(int xval, int yval, int totButtons) {
Panel myPanel = new Panel();
myPanel.setLayout(new GridLayout(xval, yval));

Button bArray[] = new Button[totButtons];
for (int x = 0; x < bArray.length; x++) {
bArray[x] = new Button(" button " + x);
myPanel.add(bArray[x]);
}
add(myPanel);
setSize(600,400);
setVisible(true);
addWindowListener( new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}

public static void main(String args[]) {
int xval = Integer.parseInt(args[0]);
int yval = Integer.parseInt(args[1]);
int totButtons = 0;
if (args.length == 3)
totButtons = Integer.parseInt(args[2]);
new DynaGrid(xval, yval, totButtons);
}
}
[This message has been edited by Joe Java (edited February 16, 2000).]
[This message has been edited by Joe Java (edited February 16, 2000).]
 
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic