您的位置:首页 > 其它

SWT(JFace)体验之Label的几种效果

2009-06-23 17:55 585 查看
演示代码:

接着前面的例子:http://blog.csdn.net/kunshan_shenbin/archive/2009/06/23/4291846.aspx

LabelWrap.java

package swt_jface.demo1;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class LabelWrap {
public LabelWrap() {

Display display = new Display();
Shell shell = new Shell(display);

String text = "Professional Java Interfaces With SWT/JFace, by Jack Li Guojie";

Label labelNoWrap = new Label(shell, SWT.BORDER);
labelNoWrap.setText(text);
labelNoWrap.setBounds(10, 10, 100, 100);

Label labelWrap = new Label(shell, SWT.WRAP | SWT.BORDER);
labelWrap.setText(text);
labelWrap.setBounds(120, 10, 100, 100);

shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new LabelWrap();
}
}


LabelSeparator.java

package swt_jface.demo1;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class LabelSeparator {

Display display = new Display();
Shell shell = new Shell(display);

Image image = new Image(display, "C:/eclipse32.gif");
public LabelSeparator() {
shell.setLayout(new RowLayout());

Label label = new Label(shell, SWT.BORDER);
// Label label = new Label(shell, SWT.SEPARATOR);
label.setImage(image);
label.setText("Label");
label.setBounds(10, 10, 150, 150);

CLabel clabel = new CLabel(shell, SWT.SHADOW_IN);
clabel.setImage(image);
clabel.setText("CLabel");
clabel.setBounds(170, 10, 150, 150);

shell.pack();
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new LabelSeparator();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: