Java Description

Can anyone explain below line of code
and
What is here 2,3,4,5 means ?
=============================
BPanel.setLayout( new GridLayout( 2, 3, 4, 5  ) );

gauravflameAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ksivananthConnect With a Mentor Commented:
>>I think by Default layout manager is Border Layout in Java swing

 it depends the container. For e.g., JFrame and JDialog uses BorderLayout and JPanel uses FlowLayout.

>>If  BPanel setting itself to Border layout why it is need to set on Grid Layout.

If BPanel is a JPanel, it will use the FlowLayout which lays the component row and wrapps if the size doesn't fit and you won't have control. grid gives you some control to render the component int tabuler format!

0
 
gauravflameAuthor Commented:
Rephrasing it is look like

contentpane.add( BPanel , BorderLayout.CENTER ) ;  // put on the content pane
BPanel.setLayout( new GridLayout( 5, 3, 5, 5  ) );
   
0
 
CEHJConnect With a Mentor Commented:
2 rows, 3 cols, 4 x pixels space, 5 y pixels space
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
objectsConnect With a Mentor Commented:
2 row x 3 column grid
with 4 pixel gap between cells horizontally
and 5 pixel gap between cells verically

http://java.sun.com/javase/6/docs/api/java/awt/GridLayout.html#GridLayout(int,%20int,%20int,%20int)
0
 
objectsCommented:
> BPanel.setLayout( new GridLayout( 5, 3, 5, 5  ) );

Thats setting the layout of BPanel to be a 5 x 3 grid
0
 
objectsCommented:
And 5 pixel gap between cells
0
 
CEHJCommented:
(Make the necessary adjustments since yours ;-))
0
 
ksivananthCommented:
2 number of rows, 3 number of columns, 4 horizontal gap between cells, 5 vertical gap between cells
0
 
gauravflameAuthor Commented:
Why to use GridLayout ? Buttons are arranged for BPanel from BorderLayout
BPanel.setLayout( new GridLayout( 5, 3, 5, 5  ) );

Observation ::
If I comment out Gridlayout  line of code everything on contentpane become scatter
0
 
objectsCommented:
no, content pane uses a border layout.
BPanel by default would use a flow layout
0
 
gauravflameAuthor Commented:
I think by Default layout manager is Border Layout in Java swing

My Question If  BPanel setting itself to Border layout why it is need to set on Grid Layout.
or It is to deal with good interface

0
 
CEHJCommented:
>>
My Question If  BPanel setting itself to Border layout why it is need to set on Grid Layout.
or It is to deal with good interface
>>

Because a BorderLayout wouldn't lay out the buttons in a neat grid
0
 
gauravflameAuthor Commented:
Thanks all clear :)


0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.