Java Code

import javax.swing.*;
public class BoxLayoutInJPanel extends JApplet
{
    JButton one, two, three;

    public void init( )
    {
        setLayout( new BoxLayout( getContentPane( ), BoxLayout.X_AXIS ) );
    	 one = new JButton( "one" );
    	 two = new JButton( "two" );
    	 three = new JButton( "buckle my shoe" );

        JPanel verticalPanel = new JPanel( );
        verticalPanel.setLayout( new BoxLayout( verticalPanel, BoxLayout.Y_AXIS ) );
        verticalPanel.add( new JButton ( "abc" ) ) ;
        verticalPanel.add( new JButton( "def" ) );
        verticalPanel.add( new JButton( "ghi" ) );
        add( verticalPanel );

        add( one );
		add( two );
		add( three );
    }
}

Back to Code Examples
©2006- by E.S.Boese. All Rights Reserved