Softbear Inc. Consulting Services

XmFormLayout.java

XMFORMLAYOUT is a freeware Java layout manager that arranges an applet's display components (e.g. buttons, choice menus, lists, text areas, text fields, etc.) according to constraints. It was inspired by Motif's XmForm widget, and has similar functionality (except that it works with Java not Motif).

A working familiarity with the XmForm widget is helpful if you wish to understand the this layout manager. It's main benefit is that it gracefully resizes and repositions display components when the containing window is sized differently.

The three examples below illustrate how XmFormLayout will size and position display components differently as the applet's window size is varied. In these examples, there are four display components:

  • Tweedle (text area, top left)
  • Dee (text area, top right)
  • Humpty (button, bottom left)
  • Dumpty (button, bottom right)

The constraints (see TestXFL.java) are:

	String constraints[] = {
		"Humpty.bottom=form.bottom-23",
		"Humpty.left=form.left+21",
		"Humpty.right=Tweedle.right",
		"Tweedle.left=Humpty.left",
		"Tweedle.top=form.top+24",
		"Tweedle.bottom=Humpty.top-10",
		"Dumpty.bottom=Humpty.bottom",
		"Dumpty.left=Humpty.right+30",
		"Dumpty.right=form.right-22",
		"Dumpty.top=Humpty.top",
		"Dee.bottom=Tweedle.bottom",
		"Dee.top=Tweedle.top",
		"Dee.left=Dumpty.left",
		"Dee.right=Dumpty.right",
	};

Example 1: Applet Window's Width is 90% Height is 300

Example 2: Applet Window's Width is 75% Height is 275

Example 3: Applet Window's Width is 65% Height is 250

The source files are below (click here to download them):