SWT示例
SWT示例

SWT示例是用SWT編寫的有用的小程序。這些通常比SWT Snippets更大,更全面。
可以從Eclipse下載頁面下載以下SWT示例:
- ControlExample
- CustomControlExample
- 地址簿
- BrowserExample
- ClipboardExample
- DNDExample(拖放)
- FileViewer
- GraphicsExample
- HelloWorld [1-5]
- HoverHelp
- ImageAnalyzer
- JavaViewer
- LayoutExample
- PaintExample
- 文本編輯器
- OLEExample(僅限win32,OLE)
- OleWebBrowser(僅限win32,OLE)
ControlExample,CustomControlExample,LayoutExample和PaintExample也可用作Eclipse插件,以下示例僅作為Eclipse插件提供:
- org.eclipse.swt.examples.browser.demos項目中的BrowserDemo
- org.eclipse.swt.examples.browser項目中的WebBrowser
有幾種方法可以下載和運行SWT示例:
- 在Eclipse中運行,可以在示例視圖中或從SWT Example Launcher視圖中運行。
- 從Eclipse中作為獨立應(yīng)用程序啟動。
- 在Eclipse之外作為獨立應(yīng)用程序運行。
在Eclipse中運行SWT示例
- 要獲取示例,請訪問 http://download.eclipse.org/eclipse/downloads上的Eclipse下載頁面。
- 單擊您想要示例的Eclipse構(gòu)建(即您正在運行的Eclipse構(gòu)建;通常是最新的Stable構(gòu)建)。
- 向下滾動,直到看到“示例插件”。閱讀有關(guān)安裝它們的段落,并選擇適合您平臺的下載。
- 安裝示例后,您可以在其中找到它們的源代碼
eclipse/plugins/org.eclipse.swt.examples.<exampleName>.source_<version>.jar。 - 要運行插件SWT示例,請重新啟動Eclipse,轉(zhuǎn)到Window> Show View ...> Other ...并展開“SWT示例”。
或者,您可以使用Eclipse ISV doc中的這些(更詳細的)步驟來下載,安裝和運行Eclipse SWT示例:
在Eclipse中啟動獨立的SWT示例
- 將SWT加載到工作區(qū)中。
- 通過上面列出的方法之一將SWT示例加載到工作區(qū)中。
- 通過選擇主類(例如org.eclipse.swt.examples.controlexample.ControlExample)并且選擇運行獨立示例
運行>運行方式> Java應(yīng)用程序(注:到Eclipse 3.3使用之前 運行>運行方式> SWT的應(yīng)用)。
在Eclipse之外運行獨立的SWT示例
(注意:這些說明僅適用于Eclipse 3.3及更高版本)要獨立運行ControlExample或CustomControlExample:
轉(zhuǎn)到 http://download.eclipse.org/eclipse/downloads/上的Eclipse下載頁面。
單擊您想要示例的Eclipse構(gòu)建(即您正在運行的Eclipse / SWT構(gòu)建;通常是最新的Stable Build)。
向下滾動,直至看到“示例插件”,下載適用于您平臺的.zip,然后將其解壓縮到本地計算機。
在具有提取的示例插件的目錄中,查找文件
org.eclipse.swt.examples_<version>.jar,并將其解壓縮到位。打開DOS窗口(在Windows上)或終端窗口(在Mac或Linux上)并導(dǎo)航到此目錄。
-
若要運行該示例,請鍵入以下行,并替換相應(yīng)的路徑:
<pathToYourJRE>\bin\java -classpath <pathOfYourPlatformSWTjar>;.\swtexamples.jar org.eclipse.swt.examples.controlexample.ControlExample這是ControlExample。每個控件都有一個選項卡,您可以更改各種樣式等,以查看控件中的更改。要運行CustomControlExample,只需在步驟6中使用類名CustomControlExample而不是ControlExample。
nstalling the examples
Installing examples within Eclipse
The Eclipse SDK examples are found on the Eclipse project update site. To locate and install them into a product:
-
Open the main install wizard by clicking [command link
Help > Install New Software...](javascript:executeCommand("org.eclipse.equinox.p2.ui.sdk.install")). This opens the Install Wizard.
Select The Eclipse Project Updates site.
Ensure Group items by category is unchecked.
Type "Eclipse SDK Examples" in the search field.
Select "Eclipse SDK Examples" and click Next.
Review the items being installed, and click Next.
Review and accept the license terms, and click Finish.
Click Yes when asked to exit and restart the workbench for the changes to take effect. The examples are now installed in the workbench. Note: you can also click on Apply Now to dynamically install the examples into the current configuration.
Installing examples manually
To install the examples from a stand-alone zip file:
- Download the appropriate Eclipse SDK Example zip file from the Eclipse project web site at http://download.eclipse.org/eclipse.
- Extract the contents of the zip file to a new empty directory inside the <tt>dropins</tt> directory of your Eclipse installation.
- Start or restart Eclipse.
You can verify that examples have been installed by looking for File > New > Example... in the workbench menu bar.
