BoxLayout in Java

BoxLayout organizes components horizontally or vertically(rows or a column) means components are placed top-to-bottom or left-to-right in the order in which they are added to the container.

 

 

X_AXIS(rows) or Y-AXIS(column), specifies whether the components are laid out horizontally or vertically.

import java.awt.*;

import javax.swing.*;

public class boxlayout1 extends JApplet

{

   public void init()

   {

       Container contentPanee = getContentPane();

       JPanel JpanelA1, JpanelB2, JpanelC3;

       JpanelA1 = new JPanel();

       JpanelB2 = new JPanel();

       JpanelC3 = new JPanel();

      

       JpanelA1.setLayout(new BoxLayout(JpanelA1, BoxLayout.Y_AXIS));

       JpanelB2.setLayout(new BoxLayout(JpanelB2, BoxLayout.X_AXIS));

       JpanelC3.setLayout(new BoxLayout(JpanelC3, BoxLayout.Y_AXIS));

       contentPanee.setLayout(new FlowLayout());

       JpanelA1.add(new JTextField("Text A1"));

       JpanelA1.add(new JTextField("Text A2"));

       JpanelA1.add(new JTextField("Text A3"));

       JpanelA1.add(new JTextField("Text A4"));

       JpanelB2.add(new JTextField("Text B1"));

       JpanelB2.add(new JTextField("Text B2"));

       JpanelB2.add(new JTextField("Text B3"));

       JpanelB2.add(new JTextField("Text B4"));

       JpanelC3.add(new JTextField("Text C1"));

       JpanelC3.add(new JTextField("Text C2"));

       JpanelC3.add(new JTextField("Text C3"));

       JpanelC3.add(new JTextField("Text C4"));

       contentPanee.add(JpanelA1);

       contentPanee.add(JpanelB2);

       contentPanee.add(JpanelC3);

   }

}

BoxLayout in Java

/*

<APPLET

   CODE = "boxlayout1.class"

   WIDTH = 250

   HEIGHT = 200 >

</APPLET>

*/

About Us

Rekha SetiaRekha Setia is a passionate blogger of Extra Computer Notes. if you have any ideas or any request me @