Source Code : BoxLayout puts components into a row or into a column

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

BoxLayout puts components into a row or into a column

 

import java.awt.Dimension;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class TwoButtons {
    public static void main(String[] args) {
      JFrame f = new JFrame();
      JPanel basic = new JPanel();
      basic.setLayout(new BoxLayout(basic, BoxLayout.Y_AXIS));
      f.add(basic);

      basic.add(Box.createVerticalGlue());

      JPanel bottom = new JPanel();
      bottom.setAlignmentX(1f);
      bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS));

      JButton ok = new JButton("OK");
      JButton close = new JButton("Close");

      bottom.add(ok);
      bottom.add(Box.createRigidArea(new Dimension(5, 0)));
      bottom.add(close);
      bottom.add(Box.createRigidArea(new Dimension(15, 0)));

      basic.add(bottom);
      basic.add(Box.createRigidArea(new Dimension(0, 15)));

      f.setSize(300, 250);

      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setVisible(true);
    }
}

   
  

Thank with us