美文网首页扣丁学堂Java培训
扣丁学堂Java在线教程之SWT(JFace) 体验之FontR

扣丁学堂Java在线教程之SWT(JFace) 体验之FontR

作者: 994d14631d16 | 来源:发表于2018-06-27 11:38 被阅读0次

本篇文章扣丁学堂Java培训小编主要和大家分享一下SWT(JFace) 体验之FontRegistry,喜欢Java开发的小伙伴可以随着小编一起来了解下。

扣丁学堂Java在线教程

测试代码如下:

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在线教程小编给大家分享的SWT(JFace) 体验之FontRegistry,希望对小伙伴们有所帮助,想要了解更多内容的小伙伴可以登录扣丁学堂官网咨询。扣丁学堂是专业的Java培训机构,不仅有专业的老师和与时俱进的课程体系,还有大量的Java在线教程供学员观看学习,想要学习Java的小伙伴快快行动吧。

相关文章

网友评论

    本文标题:扣丁学堂Java在线教程之SWT(JFace) 体验之FontR

    本文链接:https://www.haomeiwen.com/subject/wpdbyftx.html