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

2018-06-05 14:06:38 365浏览

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


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


测试代码如下:



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技术交流群:670348138。


扣丁学堂微信公众号

【关注微信公众号获取更多学习资料】



查看更多关于“Java开发资讯的相关文章>>



标签: 扣丁学堂Java在线教程 SWT(JFace) 体验之FontRegistry Java培训 Java基础教程 Java学习视频 Java教学视频 java入门教程 Java教程视频 java在线学习 java在线视频 java在线教程

热门专区

暂无热门资讯

课程推荐

微信
微博
15311698296

全国免费咨询热线

邮箱:codingke@1000phone.com

官方群:148715490

北京千锋互联科技有限公司版权所有   北京市海淀区宝盛北里西区28号中关村智诚科创大厦4层
京ICP备12003911号-6   Copyright © 2013 - 2019

京公网安备 11010802030908号