Disclaimer
Frank is a software engineer in north California. This is a personal web site. The opinions expressed here represent my own but not those of my employer. You can find him on Twitter too.
Recent Comments
- don on How to read cassandra source code by Ran
- lin1987www on Tutorial: Create android gradle project with dagger
- frankdu on Tutorial: Create android gradle project with dagger
- frankdu on Tutorial: Create android gradle project with dagger
- devender kumar on Tutorial: Create android gradle project with dagger
-
Recent Posts
Categories
Archives
- February 2019
- January 2014
- November 2013
- September 2013
- January 2013
- July 2011
- April 2011
- March 2011
- February 2011
- January 2011
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
Meta
Monthly Archives: September 2009
Quick Example to Java Scripting Engine
Have you heard that Java support scripting engine? Try the source code below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class TestScript { public static void main(String[] args) { String script = "println('Hello, world');"; script += "s=0;"; script += "for(var i=1; i<=100; i++)"; script += "s += i;"; script += "println('s='+s);"; ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("JavaScript"); try { engine.eval(script); } catch (ScriptException e) { e.printStackTrace(); } } } |
Eclipse: Dynamically Adjust Widget Size and Reflow a Form Page
Let’s say you need to dynamically adjust a widget size, and then update scroll bar information. Things are pretty simple, if we understand how eclipse layout works. I have a PageBook widget, and wish to resize the form page as … Continue reading
Posted in eclipse, java
Leave a comment
Code Snippet to use PageBook
Below is very straightforward code snippet to use PageBook. It is used together with eclipse form. Therefore you will see widgets are created via the FormToolkit class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
toolkit = new FormToolkit(container.getDisplay()); form = toolkit.createScrolledForm(container); Composite parent = form.getBody(); GridLayoutFactory.fillDefaults().numColumns(1).applyTo(parent); // create a table as selection provider final Table table = toolkit.createTable(parent, SWT.BORDER | SWT.VIRTUAL); table.setHeaderVisible(true); table.setLinesVisible(true); for(int i=1; i<=12; i++){ TableItem item = new TableItem(table, 0); item.setText("Item " + i); } toolkit.createLabel(parent, "Selected pagebook:"); // create a PageBook final ScrolledPageBook pageBook = toolkit.createPageBook(parent, SWT.NONE); GridDataFactory.defaultsFor(pageBook).grab(true, true).applyTo(pageBook); // create PageBook controls for(int i=0; i<table.getItemCount(); i++){ TableItem item = table.getItem(i); Composite pageContainer = pageBook.createPage(item.getText()); GridLayoutFactory.fillDefaults().numColumns(1).applyTo(pageContainer); toolkit.createLabel(pageContainer, item.getText()); toolkit.createText(pageContainer, "to be edited"); pageBook.showPage(item.getText()); } pageBook.showEmptyPage(); // add selection listener, and show relative PageBook on selection table.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e) { TableItem item = (TableItem) e.item; pageBook.showPage(item.getText()); } }); |