by Dinesh Thakur Category: Swing

Glue is an invisible component which is similar to a strut but it pushes the components as far away from each other as possible within the bounds of the box itself. You create an invisible component that represents Glue by calling the createGl ue () method for a Box object For example: The statements

b. add (new JButton ("C")) ;

b.add(Box.createGlue());

b.add(new JButton(“C++"));

b.add(new JButton("Visual Basic"));

b.add(new JButton(“Java"));

move the second third and fourth buttons as far away from the first button as possible, based on the height of the box.

import javax.swing.*;

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

GLUE in Java Swing Example



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content





Popular Article