SWT标签Label垂直居中的方法
来源:优易学  2011-2-17 10:38:42   【优易学:中国教育考试门户网】   资料下载   IT书店
  一不小心发现的,竟然可以用哦。当然,大侠们可能早就知道了。
  package com.laozizhu.search.client.test;
  import org.eclipse.swt.SWT;
  import org.eclipse.swt.custom.CLabel;
  import org.eclipse.swt.graphics.Image;
  import org.eclipse.swt.widgets.Display;
  import org.eclipse.swt.widgets.Shell;
  /**
  * SWT中,Label垂直居中,水平居中的方法.
  *
  * @author examda
  */
  public class LabelVerticleMiddle {
  Display display = new Display();
  Shell shell = new Shell(display);
  Image image = new Image(display, "laozizhu.png");
  public LabelVerticleMiddle() {
  // 一不小心发现,这个SAHDOW竟然可以垂直居中哦。
  CLabel clabel = new CLabel(shell, SWT.SHADOW_NONE);
  clabel.setAlignment(SWT.CENTER);
  clabel.setImage(image);
  clabel.setText("考试大家一起努力哦");
  clabel.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
  clabel.setBounds(10, 10, 150, 150);
  shell.setSize(180, 200);
  shell.open();
  // Set up the event loop.
  while (!shell.isDisposed()) {
  if (!display.readAndDispatch()) {
  // If no more entries in event queue
  display.sleep();
  }
  }
  display.dispose();
  }
  public static void main(String[] args) {
  new LabelVerticleMiddle();
  }
  } 

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训