By Alvin Alexander. Last updated: June 6, 2016
This code shows how to create a Java FlowLayout
that flows left and has horizontal spacing of ten pixels and vertical spacing of five pixels:
FlowLayout flowLayout = new FlowLayout(FlowLayout.LEFT, 10, 5); jPanel.setLayout(flowLayout);
Here’s what the FlowLayout
constructor arguments look like:
FlowLayout(int align, int horizontalSpacing, int verticalSpacing);
FlowLayout 'align' property definitions
The align
property can be any of these:
- LEFT
- CENTER
- RIGHT
- LEADING
- TRAILING
Here are the definitions for those align
properties from the FlowLayout Javadoc:
LEFT - each row of components should be left-justified CENTER - each row of components should be centered RIGHT - each row of components should be right-justified LEADING - each row of components should be justified to the leading edge of the container's orientation, for example, to the left in left-to-right orientations TRAILING - each row of components should be justified to the trailing edge of the container's orientation, for example, to the right in left-to-right orientations
Without writing some code, I honestly have no idea what LEADING
and TRAILING
actually do. Other than that caveat, if you needed to know about how set a Java FlowLayout
to flow, and also to set its horizontal and vertical spacing properties, I hope this is helpful.