> Java > tools > ui > blox
> Java > tools > ui > blox
by ZweiBieren Blox Beats Box for Layout nested boxes with BLOX inside
   
BloxLayout, like its namesake BoxLayout, either stacks its components in a column or ranges them in a row. At right is a vertical Blox combining a label, a text area and an inner Blox showing two buttons.

Blox provides all the same constructors and methods as Box. If you textually replace "Box" with "Blox" in a working program, the program will continue to compile and run. So if you know Box you can use Blox. However, there are significant differences:

A title, a scrollable text area, and two buttons
The code, just below,
exactly mirrors this page layout
  • Blox exploits varargs to streamline construction code. The code for the example above is shown at the right; it follows line for line the image on the screen.
return Blox.createVerticalBlox(
   new JLabel("How do you do it?"),
   new JScrollPane(
         new JTextArea(1,15)),
   Blox.createHorizontalBlox(
      new JButton("Submit"),
      new JButton("Cancel")
   )
);
  • Blox implements different (better!) defaults for spacing and alignment. An alignment of LEFT_ALIGNMENT actually aligns the iterm on the left. (Compare with the Box diagram.)
JTextFields shown with various alignment values
  • You manage layout options by inserting Blox.Note elements in the varargs lists. To add space between the buttons you add the note shown in bold on the right.
Blox.createHorizontalBlox(
    new JButton("Submit"),
    Blox.strut(13),
    new JButton("Cancel")
)
  • BloxSection delimiters can control how space is distributed between the Components. In the application shown at the right, the blue rectangle is in a "thin" section. Its width is adjusted so the four quarters meet at a point even when the image is replaced with another of a different size.
Nausithoe Punctata
  • Blox offers a factory to create all four component orientations. The image at the right is generated by calling the same method four times, and each time applying a different component orientation to the result.
four components aligned in a horizontal Blox
   
src Jdoc class note
Java steaming cup doc with "J" Blox.java Methods for composing windows in rectangular layouts; like Box
Java steaming cup doc with "J" BloxLayout.java Lays out rectangles managed by Blox
Java steaming cup doc with "J" BloxReq.java Requested sizes for a componnt
Java steaming cup doc with "J" BloxSection.java Manage sections of sequential components of a Blox
 
Copyright © 2018 ZweiBieren, All rights reserved. Oct 9, 2018 18:12 GMT Page maintained by ZweiBieren