| |
17. 9. 17. 设置调整文本/图像标签按钮 |
|
Set the alignment of the text/image label of a button in the constructor of the Button class, or you can use the setAlignment method after it has been created: |
public void setAlignment(int alignment)
|
|
To query a button for its label alignment, call the getAlignment method: |
public int getAlignment()
|
|
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class ButtonAlignment {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display, SWT.SHELL_TRIM);
shell.setLayout(new FillLayout());
Button button = new Button(shell, SWT.RIGHT);
button.setText("text on the button");
button.setAlignment(SWT.CENTER);
shell.open();
// Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
// If no more entries in event queue
display.sleep();
}
}
display.dispose();
}
}
|
|
|