Open Source JavaFX Now!

JFXtras Core Logo

Layouts

Layouts and Resizable Containers are provided to handle Stage, Scene and Component resizing, maintaining logical positioning and sizing across the desired component range.

The following classes are available:

  • MigLayout - Use MigLayout to size and position nodes.
  • XCustomNode - Easily create JFXtras compatible CustomNodes
  • XGrid - Powerful and versatile Grid layout with a declarative syntax
  • XHBox & XVBox - HBox and VBox implementations that resize their contents
  • XScene - Drop-in replacement for Scene that will automaticlaly resize its children
  • XStack - Stack implementation that will propogate up JFXtras layout defaults

The JFXtras Default System

All of the JFXtras Controls are pre-configured with default layout options that will give you reasonable results when put directly in a layout container. For example, the JFXtras XPicker will fill horizontal and vertical, align left, and grow horizontally (sometimes). There are also defaults built-in for all the core JFXtras controls, so those will work together seamlessly.

This gives you the ability to layout forms or simple bordered layouts without worrying about setting up a lot of configuration.

Defaults will also propagate up the chain, trickling through parent contains, so you can safely nest your components in XStacks, XBoxes, or other layout containers without worrying about the defaults getting obscured.

Layout Constraints

All the JFXtras Layouts support a common set of layout constraints. These include the standard JavaFX LayoutInfo parameters, plus a set of additional extensions that are only supported by JFXtras layouts.

LayoutInfo Constraints (supported by all JavaFX Layouts):

ConstraintTypeDefaultDescription
hposHPosCENTERThe horizontal alignment of the Node within its Cell
vposVPosCENTERThe vertical alignment of the Node within its Cell

XLayoutInfo Constraints (supported by all JFXtras Layouts):

ConstraintTypeDefaultDescription
marginInsetsinsets(0)Allows you to set a margin around the Node
hfillBooleanfalseWhether or not the Node will fill available horizontal space within its Cell
vfillBooleanfalseWhether or not the Node will fill available vertical space within its Cell
hgrowPriorityNEVERWhether or not the Node's Cell bounds will grow horizontally
vgrowPriorityNEVERWhether or not the Node's Cell bounds will grow vertically
hshrinkPrioritySOMETIMESWhether or not the Node's Cell bounds will shrink horizontally
vshrinkPrioritySOMETIMESWhether or not the Node's Cell bounds will shrink vertically

XGridLayoutInfo Constraints (supported by the JFXtras XGridLayout):

ConstraintTypeDefaultDescription
hspanInteger1Number of cells that will be spanned horizontally
vspanInteger1Number of cells that will be spanned vertically

Writing JFXtras Compatible Controls

All the usual best practices for writing JavaFX Controls applies, but if you do a few additional steps your control will also take advantage of the full power of the JFXtras Default System.

Steps:

  1. Make sure your control extends DefaultLayout (in the org.jfxtras.scene.layout package)
  2. Override or set the defaultLayoutInfo variable to an instance of XLayoutInfo
  3. Set only the XLayoutInfo properties that you want to override

Example:


public class XPicker extends Control, DefaultLayout { override var defaultLayoutInfo = XLayoutInfo { hfill: true vfill: true hgrow: SOMETIMES hpos: LEFT } }

<< Back to JFXtras FrontPage

0 Attachments 0 Attachments
4454 Views