SWT's RowLayout is fine for the purpose, however I'd like the vertical alignment on the font baseline for all widgets containing text.
Is there maybe a ready custom Layout that does this?
Snippet204.java probably has what it takes to implement it, but I just want to ask if it has been done before. Couldn't find it, but it seems like a typical requirement.
In the screenshot's top, there's the row layout, below is a fixed layout that I manually arranged to the baseline (WindowBuilder has snapping for that).
RowLayout
has a field called center
. Just set it to true
and you're good.
center
specifies whether the controls in a row should be centered vertically in each cell for horizontal layouts, or centered horizontally in each cell for vertical layouts. The default value isfalse
.
public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
RowLayout layout = new RowLayout();
layout.center = true;
shell.setLayout(layout);
shell.setText("StackOverflow");
new Label(shell, SWT.NONE).setText("Label");
new Button(shell, SWT.PUSH).setText("Button");
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With