Search code examples
javauser-interfaceborder-layout

What do the parameters of BorderLayout signify?


I have been searching on the Internet for a straight answer but cannot find the specific answer I'm after. Apologies if this is basic question, I was hoping someone could help explain with an example.

Essentially, I'd like to know the difference between the two lines of code below:

JPanel panel1 = new JPanel(new BorderLayout(4,4));

JPanel panel2 = new JPanel(new BorderLayout(3,3));

Any help or guidance would be greatly appreciated.

Thanks


Solution

  • The first parameter of the BorderLayout constructor is the horizontal gap, the second is the vertical gap.

    Check this tutorial for more information on how to use BorderLayout : http://docs.oracle.com/javase/tutorial/uiswing/layout/border.html

    You should also check the documentation for more information about BorderLayout : http://docs.oracle.com/javase/7/docs/api/java/awt/BorderLayout.html