欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SWT/JFace 核心应用-标签

程序员文章站 2022-06-14 14:53:56
...

文本标签

Label label = new Label(compositeUp,SWT.RIGHT);

分割线标签

Label label1 = new Label(compositeUp,SWT.SEPARATOR|SWT.HORIZONTAL|SWT.SHADOW_OUT);

创建分割线指定样式为SEPARATOR,不指定方向默认垂直分割线SWT.VERTICAL,分割线三种外观 SWT.SHADOW_IN,SWT.SHADOW_OUT,SWT.SHADOW_NONE

自定义标签

Lable 标签类不能讲图标和文字同时显示,可以使用 org.eclipse.swt.custom.CLabel 类

CLabel cLabel = new CLabel(compositeUp,SWT.LEFT);
cLabel.setText(“自定义标签”);
cLabel.setImage(display.getSystemImage(SWT.ICON_INFORMATION));

测试代码

 public static void main(String[] args) {
        Display display = Display.getDefault();
        Shell shell=new Shell(SWT.MIN|SWT.CLOSE);
        shell.setText("测试");
        shell.setSize(400, 200);

        shell.setLayout(new FillLayout());
        Composite compositeUp = new Composite(shell, SWT.NONE);
        compositeUp.setLayout(new GridLayout(5,false));

        Label label = new Label(compositeUp,SWT.RIGHT);
        label.setText("文本标签");

        Label label1 = new Label(compositeUp,SWT.SEPARATOR|SWT.VERTICAL|SWT.SHADOW_OUT);
        Button button = new Button(compositeUp,SWT.PUSH);
        button.setText("普通按钮");
        Label label2 = new Label(compositeUp,SWT.SEPARATOR|SWT.VERTICAL|SWT.SHADOW_IN);

        CLabel cLabel = new CLabel(compositeUp,SWT.LEFT);
        cLabel.setText("自定义标签");
        cLabel.setImage(display.getSystemImage(SWT.ICON_INFORMATION));


        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }


    }

效果图

SWT/JFace 核心应用-标签