> 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)),
      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.
    new JButton("Submit"),
    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 DESCRIBE
Java steaming cup doc with "J" BloxLayout.java DESCRIBE
Java steaming cup doc with "J" BloxReq.java DESCRIBE
Java steaming cup doc with "J" BloxSection.java DESCRIBE
Copyright © 2018 ZweiBieren, All rights reserved. Aug 10, 2018 16:38 GMT Page maintained by ZweiBieren