Java界面 SWT基本组件——Label

来源:互联网 发布:淘宝企业店铺纳税问题 编辑:程序博客网 时间:2024/04/28 07:19

标签(Label)基本类型与基本案例

SWT 的标签有两类,一类是显示普通文本或图片的标签,一类是分割线。如图所示,为两种类型的标签示意图(文本+分割线)。

代码如下:
shell.setSize(200, 200);shell.setText("SWT.SEP");shell.setLayout(new FillLayout(SWT.HORIZONTAL));RowLayout layout = new RowLayout(SWT.VERTICAL);layout.marginWidth = 10;shell.setLayout(layout);Group group = new Group(shell, SWT.SHADOW_ETCHED_OUT); group.setLayout(new FillLayout(SWT.VERTICAL));Label labelText = new Label(group, SWT.NONE);labelText.setText("这是一个有分割线的文本标签");Label label = new Label(group, SWT.NONE|SWT.SEPARATOR|SWT.HORIZONTAL);group.layout();//shell.layout();//shell.pack();shell.open();


1. 标签案例(LabelSample)

内容包含分割线(水平/垂直)、普通文本、布局宽度设置。
shell.setSize(200, 200);shell.setText("SWT.SEP&Label");shell.setLayout(new FillLayout(SWT.VERTICAL));// 设置表格布局RowLayout layout = new RowLayout(SWT.VERTICAL);layout.marginWidth = 10;// 宽度10 ????shell.setLayout(layout);// 组·文本标签Group group1 = new Group(shell, SWT.SHADOW_ETCHED_OUT);group1.setLayout(new FillLayout(SWT.VERTICAL));group1.setText("文本标签");Label label1 = new Label(group1, SWT.NONE|SWT.LEFT);label1.setText("SWT.LEFT");Label label2 = new Label(group1, SWT.NONE|SWT.CENTER);label2.setText("SWT.CENTER");Label label3 = new Label(group1, SWT.NONE|SWT.RIGHT);label3.setText("SWT.RIGHT");//group1.layout();//group1.pack();// 组·水平分割线Group group2 = new Group(shell, SWT.SHADOW_ETCHED_OUT);group2.setLayout(new FillLayout(SWT.VERTICAL));group2.setText("水平分割线:SWT.HORIZONTAL");Label label4 = new Label(group2, SWT.NONE|SWT.LEFT);label4.setText("SWT.SHADOW_IN");Label sepLabel1 = new Label(group2, SWT.SEPARATOR|SWT.HORIZONTAL|SWT.SHADOW_IN);Label label5 = new Label(group2, SWT.NONE|SWT.CENTER);label5.setText("SWT.SHADOW_OUT");Label sepLabel2 = new Label(group2, SWT.SEPARATOR|SWT.HORIZONTAL|SWT.SHADOW_OUT);Label label6 = new Label(group2, SWT.NONE|SWT.RIGHT);label6.setText("SWT.SHADOW_NONE");Label sepLabel3 = new Label(group2, SWT.SEPARATOR|SWT.HORIZONTAL|SWT.SHADOW_NONE);//group2.layout();//group2.pack();// 竖直分割线:SWT.VERTICALGroup group3 = new Group(shell, SWT.SHADOW_ETCHED_OUT);group3.setLayout(new FillLayout(SWT.HORIZONTAL));group3.setText("竖直分割线:SWT.VERTICAL");Label sepLabel4 = new Label(group3, SWT.SEPARATOR|SWT.VERTICAL|SWT.SHADOW_IN);Label sepLabel5 = new Label(group3, SWT.SEPARATOR|SWT.VERTICAL|SWT.SHADOW_OUT);Label sepLabel6 = new Label(group3, SWT.SEPARATOR|SWT.VERTICAL|SWT.SHADOW_NONE);//group3.layout();//group3.pack();shell.layout();shell.pack();shell.open();


2. 自定义标签(CLabel)

自定义标签可以实现图标和文字同时显示.

shell.setSize(200, 200);shell.setText("SWT.CLabel");shell.setLayout(new FillLayout(SWT.HORIZONTAL));CLabel cl = new CLabel(shell, SWT.LEFT);cl.setText("这是一个带有图标的自定义标签");cl.setImage(new Image(shell.getDisplay(), "f:\\icon\\rswt.png"));shell.layout();shell.pack();shell.open();

0 0
原创粉丝点击