java - How to center a Button using a FormLayout in SWT? -


how can position button (vertically) @ center using formlayout (see here)? using:

final button button = new button(shell, swt.none); button.settext("button");  final formdata layoutdata = new formdata(); layoutdata.top = new formattachment(50); layoutdata.left = new formattachment(0); layoutdata.right = new formattachment(100); button.setlayoutdata(layoutdata); 

i end

enter image description here

which not surprising, since told put top of button @ center (layoutdata.top = new formattachment(50);). how can instead put center of button @ center?

you can specify offset constructor:

new formattachment(int numerator, int offset) 

looks this:

enter image description here

you can compute offset using:

final button button = new button(shell, swt.none); button.settext("button");  final formdata layoutdata = new formdata();  /* compute offset */ int offset = -button.computesize(swt.default, swt.default).y / 2;  /* create formattachment */ layoutdata.top = new formattachment(50, offset); layoutdata.left = new formattachment(0); layoutdata.right = new formattachment(100); button.setlayoutdata(layoutdata); 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -