SWT(JFace) 体验之FontRegistry

所属分类: 软件编程 / Java编程 阅读数: 83
收藏 0 赞 0 分享
复制代码 代码如下:

package swt_jface.demo;
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class FontRegistryExample {
Display display = new Display();
Shell shell = new Shell(display);

FontRegistry fontRegistry;
public FontRegistryExample() {

init();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
private void init() {

shell.setLayout(new GridLayout(2, false));

fontRegistry = new FontRegistry(display);

fontRegistry.put("button-text", new FontData[]{new FontData("Arial", 9, SWT.BOLD)} );
fontRegistry.put("code", new FontData[]{new FontData("Courier New", 10, SWT.NORMAL)});

Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP);
text.setFont(fontRegistry.get("code"));
text.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
text.setText("public static void main() {\n\tSystem.out.println(\"Hello\"); \n}");
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2;
text.setLayoutData(gd);

Button executeButton = new Button(shell, SWT.PUSH);
executeButton.setText("Execute");
executeButton.setFont(fontRegistry.get("button-text"));

Button cancelButton = new Button(shell, SWT.PUSH);
cancelButton.setText("Cancel");
cancelButton.setFont(fontRegistry.get("button-text"));
}
public static void main(String[] args) {
new FontRegistryExample();
}
}
更多精彩内容其他人还在看

Java实现文件分割和文件合并实例

本篇文章主要介绍了Java实现文件分割和文件合并实例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

LeetCode -- Path Sum III分析及实现方法

这篇文章主要介绍了LeetCode -- Path Sum III分析及实现方法的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下
收藏 0 赞 0 分享

使用MUI框架构建App请求http接口实例代码

下面小编就为大家分享一篇使用MUI框架构建App请求http接口实例代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Java发送邮箱验证码、session校验功能

本篇主要描述“发送邮箱验证码、session校验”相关前(html\js)后(java)台代码,业务逻辑示例,需要的朋友可以参考下
收藏 0 赞 0 分享

windows下 jdk1.7安装教程图解

java编程的初学者在开始编码前都会遇到一个难题,那就是jdk1.7环境变量配置怎么操作,怎么安装,针对这个难题,小编特地为大家整理相关教程,不了解的朋友可以前往查看使用
收藏 0 赞 0 分享

JAVA演示阿里云图像识别API,印刷文字识别-营业执照识别

最近有由于工作需要,开始接触阿里云的云市场的印刷文字识别API-营业执照识别这里我加上了官网的申请说明,只要你有阿里云账号就可以用,前500次是免费的,API说明很简陋,只能做个简单参考
收藏 0 赞 0 分享

springboot 使用yml配置文件给静态变量赋值教程

这篇文章主要介绍了springboot 使用yml配置文件给静态变量赋值教程,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

关于springboot 配置文件中属性变量引用方式@@解析

这篇文章主要介绍了关于springboot 配置文件中属性变量引用方式@@解析,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

springboot yml定义属性,下文中${} 引用说明

这篇文章主要介绍了springboot yml定义属性,下文中${} 引用说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

IDEA解决Java:程序包xxxx不存在的问题

这篇文章主要介绍了IDEA解决Java:程序包xxxx不存在的问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多