Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

[an error occurred while processing this directive]

Java Notes

BoxLayout spacing

Fillers - struts, glue, rigid areas, and custom Fillers

Invisible components can be added to a BoxLayout to produce empty space between components. The most useful are struts (or rigid areas). Glue may be insert empty space to fill out a panel.
  • Struts are non-expandable, fixed-size components, either vertical or horizontal.
  • Rigid areas specify a fixed horizontal and vertical size.
  • Glue is an expandable component. Used if you want spacing to increase when a window is resized.
  • Box.Filler is a class that lets you create your own fillers with specified minimum, preferred, and maximum sizes.

Strut

   p.add(Box.createVerticalStrut(n));   // n pixels of vertical space.
   p.add(Box.createHorizontalStrut(n)); // n pixels of horizontal space.
When you want to specify space between components use a strut. Create a strut by specifying it's size in pixels, and adding it to the panel at the point you want the space between other components. Important: Use horizontal struts only in horizontal layouts and vertical struts only in vertical layouts, otherwise there will be problems.
p.add(Box.createHorizontalStrut(10));
This creates a strut component 10 pixels wide and adds it to a panel.

Rigid Area

A rigid area is very similar to a strut, but has both vertical and horizontal dimensions, consequently, a rigid area can be used in either horizontal or vertical layouts, altho often they are created with the unused size set to zero. Create a rigid area by specifying it's width and height in pixels in a Dimension object, which has two parameters, an x distance and a y distance. Typically the dimension you are not interested in is set to zero.
p.add(Box.createRigidArea(new Dimension(10, 0)));
This creates a rigid area component 10 pixels wide and 0 pixels high and adds it to a panel. This has the same effect as the horizontal strut defined above.

Glue

   p.add(Box.createVerticalGlue());    // expandable vertical space.
   p.add(Box.createHorizontalGlue());  // expandable horizontal space.
Glue is an invisible component that can expand. It's more like a spring or sponge than glue. Put a glue component where extra space should appear (disappear from) when a window is resized. Use vertical glue in a vertical BoxLayout and horizontal glue in a horizontal layout. Two methods in the Box class create glue. For example, this will allow extra vertical space between two buttons.
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
p.add(button1);
p.add(Box.createVerticalGlue()); // this will expand/contract
p.add(button2);
Use the Box.createHorizontalGlue() method for horizontal layouts.

Box.Filler

You can create your own filler by using the Box.Filler constructor and specifying the minimum, preferred, and maximum size. Each size must be in a Dimension object, which has width and height.
Box.Filler myFiller = new Box.Filler(min, pref, max);
For example, to create a new horizontal filler that can get no smaller that 4 pixels, that prefers to be 16 pixels wide, and that will expand to no more than 32 pixels, you could do this:
Box.Filler hFill = new Box.Filler(new Dimension(4,0), 
                                 new Dimension(16, 0), 
                                 new Dimension(32, 0));
Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.