2018-06-05 14:06:38 1245瀏覽
本篇文章扣丁學堂Java培訓小編主要和大家分享一下SWT(JFace) 體驗之FontRegistry,喜歡Java開發(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(); } }
以上就是扣丁學堂Java在線教程小編給大家分享的SWT(JFace) 體驗之FontRegistry,希望對小伙伴們有所幫助,想要了解更多內(nèi)容的小伙伴可以登錄扣丁學堂官網(wǎng)咨詢??鄱W堂是專業(yè)的Java培訓機構(gòu),不僅有專業(yè)的老師和與時俱進的課程體系,還有大量的Java在線教程供學員觀看學習,想要學習Java的小伙伴快快行動吧??鄱W堂Java技術(shù)交流群:670348138。
【關(guān)注微信公眾號獲取更多學習資料】
查看更多關(guān)于“Java開發(fā)資訊”的相關(guān)文章>>