by Dinesh Thakur Category: Swing

A rigid area filler is similar to pair of struts. It is an invisible component with a specific width and height. It can be created using the static method

createRigidArea(dimension)

.in the Box class. Here the dimension argument specifies the size of rigid area. For example, the statement.

b.add(Box.createRigidArea(new Dimension(10,20));

adds a rigid area 10 pixels wide and 20 pixels in height into a Box.

import javax.swing.*;

import java.awt.*;
class BoxLayout extends JFrame
{
     JButton [] Buttons;
     BoxLayout()
    {
        int i;
        Box b = Box.createVerticalBox();
        b.add(new JButton("C"));
        b.add(Box.createRigidArea(new Dimension(10,20)));
        b.add(new JButton("C++"));
        b.add(new JButton("Visual Basic"));
        b.add(new JButton("Java"));
        add(b);
     }
}
    class RigidAreaJavaExample
    {
       public static void main(String args[])
       {
           BoxLayout frame = new BoxLayout();
           frame.setTitle("RigidArea Java Example");
           frame.setBounds(200,250,250,250);
           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           frame.setVisible(true);
       }
    }

Rigid Area Filler in Java Swing Example

Popular Article