Link to home
Start Free TrialLog in
Avatar of gauravflame
gauravflame

asked on

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  ) );

Avatar of gauravflame
gauravflame

ASKER

Rephrasing it is look like

contentpane.add( BPanel , BorderLayout.CENTER ) ;  // put on the content pane
BPanel.setLayout( new GridLayout( 5, 3, 5, 5  ) );
   
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> BPanel.setLayout( new GridLayout( 5, 3, 5, 5  ) );

Thats setting the layout of BPanel to be a 5 x 3 grid
And 5 pixel gap between cells
(Make the necessary adjustments since yours ;-))
2 number of rows, 3 number of columns, 4 horizontal gap between cells, 5 vertical gap between cells
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
no, content pane uses a border layout.
BPanel by default would use a flow layout
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

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>
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
Thanks all clear :)


:-)