SWT(JFace) 體驗(yàn)之FontRegistry
更新時間:2009年06月25日 09:20:39 作者:
測試代碼如下:
復(fù)制代碼 代碼如下:
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();
}
}
相關(guān)文章
Java程序結(jié)構(gòu)與常量變量難點(diǎn)解析
JAVA的基本結(jié)構(gòu)就是順序結(jié)構(gòu),除非特別指明,否則就按照順序一句一句執(zhí)行順序結(jié)構(gòu)是最簡單的算法結(jié)構(gòu),語句與語句之間,框與框之間是按從上到下的順序進(jìn)行的,它是由若干個依次執(zhí)行的處理步驟組成的,它是任何一個算法都離不開的一種基本算法結(jié)構(gòu)2021-10-10Spring原生Rpc六種的正確打開方式實(shí)現(xiàn)示例
這篇文章主要為大家展示了Spring原生Rpc六種的正確打開方式實(shí)現(xiàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助祝大家多多進(jìn)步早日升職加薪2022-02-02MyBatis-Plus動態(tài)返回實(shí)體類示例詳解
這篇文章主要為大家介紹了MyBatis-Plus動態(tài)返回實(shí)體類示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07使用Swagger2實(shí)現(xiàn)自動生成RESTful?API文檔
在開發(fā)?RESTful?API?的過程中,文檔是非常重要的一部分,可以幫助開發(fā)者了解?API?的功能和使用方法,本文將使用Swagger2?實(shí)現(xiàn)自動生成?RESTful?API?文檔,需要的可以參考一下2023-06-06通過Java實(shí)現(xiàn)對PDF頁面的詳細(xì)設(shè)置
這篇文章主要介紹了通過Java實(shí)現(xiàn)對PDF頁面的詳細(xì)設(shè)置,下面的示例將介紹通過Java編程來對PDF頁面進(jìn)行個性化設(shè)置的方法,包括設(shè)置頁面大小、頁邊距、紙張方向、頁面旋轉(zhuǎn)等,需要的朋友可以參考下2019-07-07