Zi1mann
Zi1mann

Reputation: 344

2nd parameter of Java GridLayout(a,b,x,y)?

So Im tinkering on the Design of a simple Javaprogramm... I imported the GridLayout and created it, assembling it like this:

abc.setLayout(new GridLayout(3, 5, 10, 10))

and the 2nd parameter (5) changes nothing. (3) is the number of lines, so i thought 5 is the number of columns, while (10) & (10) describe the gaps between the cells of the grid.

So when i change the (5) nothing happens. So could you explain me what the parameter (5) stands for? And if it isnt supposed to change the number of columns, how can I change this anyways?

Thx appreciate it.

Upvotes: 0

Views: 173

Answers (1)

ProgrammingIsAwsome
ProgrammingIsAwsome

Reputation: 1129

Look at the Java API: http://docs.oracle.com/javase/7/docs/api/java/awt/GridLayout.html Here is a small example from the Java API:

import java.awt.*;
import java.applet.Applet;
public class ButtonGrid extends Applet {
     public void init() {
         setLayout(new GridLayout(3,2));
         add(new Button("1"));
         add(new Button("2"));
         add(new Button("3"));
         add(new Button("4"));
         add(new Button("5"));
         add(new Button("6"));
     }
 }

or here: http://docs.oracle.com/javase/tutorial/uiswing/layout/grid.html

And it's like @FastSnail said, add more components and you will see a change. If you just add 1 component you can't see a change when you alter the column parameter.

Upvotes: 2

Related Questions