【SWT】内容分割线

目标

SWT 容器中画横向直线或竖向直线将容器中的内容分割开来。本文介绍了官方的两个示例,效果图见实践部分。

分析

SWT 中至少由两种方法画直线(横向或纵向)

  • SWT 中的GC可以画直线

这种方法最容易想到,但实现起来比较麻烦,测出暂不介绍。

  • SWT 中的Label画直线

这种方法官方的叫法比较直接,即 分割器(Separator) ,只需要在创建 Label 时指定 style 为 SWT.SEPARATOR 即可,横向和纵向通过 SWT.HORIZONTAL 和 SWT.VERTICAL 确定 。

// 横向直线 
Label label = new Label(shell,SWT.SEPARATOR | SWT.HORIZONTAL);
// 竖向直线
Label label = new Label(shell,SWT.SEPARATOR | SWT.VERTICAL);

官方demo 地址为:
https://github.com/eclipse-platform/eclipse.platform.swt/blob/master/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet37.java

实践

代码:

import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Snippet37 {

public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);
	shell.setText("Snippet 37");
	shell.setLayout (new FillLayout ());
	new Label (shell, SWT.SEPARATOR | SWT.HORIZONTAL);
	new Label (shell, SWT.SEPARATOR | SWT.VERTICAL);
	shell.setSize (200, 200);
	shell.open ();
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}

效果
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值