Tuning min and max size properties

JavaFX provides a convenient approach to component sizes with properties: min, preferred, and max. These values are used by layout managers to represent their children.

Let's take a button, for example. A button's width is governed by the length of the text inside; on the other hand, a button can't outgrow its container so text may be shortened if there is not enough space—these are natural constraints, but you can impose extra ones by setting setMinWidth() and setMaxWidth().

Let's see in code how different size constraints work in JavaFX:

// chapter7/resising/MinMaxSizeDemo.javaButton btnNoMin = new Button("I have no min width");Button btnMin = new Button("I have min width");btnMin.setMinWidth(100);Button ...

Get Mastering JavaFX 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.