SWT(JFace) 体验之FontRegistry

所属分类: 软件编程 / Java编程 阅读数: 93
收藏 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 Swing之游戏设计(1)

跟我学Java Swing之游戏设计(1)
收藏 0 赞 0 分享

选择java的理由:java之父访谈实录

选择java的理由:java之父访谈实录
收藏 0 赞 0 分享

面向对象编程:Java中的抽象数据类型

面向对象编程:Java中的抽象数据类型
收藏 0 赞 0 分享

通过JDBC连接oracle数据库的十大技巧

通过JDBC连接oracle数据库的十大技巧
收藏 0 赞 0 分享

一个MIDP俄罗斯方块游戏的设计和实现

一个MIDP俄罗斯方块游戏的设计和实现
收藏 0 赞 0 分享

使用Spring来创建一个简单的工作流引擎

这篇文章主要给大家介绍了关于使用Spring来创建一个简单的工作流引擎的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

Toolbar制作菜单条过程详解

Toolbar制作菜单条过程详解
收藏 0 赞 0 分享

Windows+Apache+resin配置

Windows+Apache+resin配置
收藏 0 赞 0 分享

JDK的命令详解

JDK的命令详解
收藏 0 赞 0 分享

Java中的浮点数分析

Java中的浮点数分析
收藏 0 赞 0 分享
查看更多