📄 index.html
字号:
manager.</small><br>
<small></small><br>
<small>Add a Button and CLabel as shown, and anchor them so the label
stretches both ways and the button is anchored to the bottom-right.</small><br>
<small><img
src="file:///C:/workspace-jigloo/jigloo/html/swt_tutorial/about_dialog1.png"
title="" alt="" style="width: 376px; height: 145px;"><br>
<br>
<br>
</small></div>
<small><span style="font-weight: bold;">A bit about properties</span></small><br>
<br>
<div style="margin-left: 40px;"><small>Now, use the property editor to
set the CLabel's alignment to CENTER</small><br>
<small></small><br>
<small><img
src="file:///C:/workspace-jigloo/jigloo/html/swt_tutorial/center_align.png"
title="" alt="" style="width: 244px; height: 208px;"></small><br>
<small></small><br>
<small>Since we are in the property editor, we should take a moment to
look at
property "categories" which organise properties into "Basic", "Expert",
"Hidden" and any other category you might want to create. For instance,
if you scroll down a bit in the property list you'll see the "Expert"
category, and a property "backgroundImage". You may want to use this
property a lot and so move it to the "Basic" category. You can do this
by simply right-clicking on a property name and choosing the category
you want from the list (see below).</small><br>
<small></small><br>
<small><img
src="file:///C:/workspace-jigloo/jigloo/html/swt_tutorial/prop_category.png"
title="" alt="" style="width: 484px; height: 219px;"></small><br>
</div>
<small><br>
</small><small><span style="font-weight: bold;"><br>
Back to the dialog</span></small><br>
<small></small><br>
<div style="margin-left: 40px;"><small>Now, just to demonstrate the
"Surround by" feature, right-click on the label and choose "Surround by
container...->CTabFolder"<br>
<br>
<img src="surround_by.png" title="" alt=""
style="width: 458px; height: 182px;"><br>
<br>
Then add a new CTabItem (from the "Items" palette) to the newly-created
CTabFolder, add a CLabel to the CTabItem<br>
<br>
<img src="add_ctabitem.png" title="" alt=""
style="width: 282px; height: 217px;"><br>
</small><small><br>
<br>
</small></div>
</div>
<div style="margin-left: 40px; font-family: tahoma;"><small><span
style="font-weight: bold;">Add code to dispose dialog<br>
<br>
</span></small>
<div style="margin-left: 40px;"><small>Now, select the OK button and
find the "Events" section in the "GUI Properties" view. Then scroll
down and open the "SelectionListener" node, and set "widgetSelected" to
"inline"<br>
<img src="selected_event.png" title="" alt=""
style="width: 247px; height: 186px;"><br>
<br>
Jigloo will flip to the source code editor, at the place where the
widgetSelected event handler has been inserted. Edit the code to add <br>
</small>
<pre style="font-weight: bold;">dialogShell.dispose()</pre>
<small>as shown, so that the dialog will close when the OK button is
hit.<br>
<br>
<img src="dispose_code.png" title="" alt=""
style="width: 574px; height: 157px;"><br>
<br style="font-weight: bold;">
</small></div>
</div>
<div style="margin-left: 40px; font-family: tahoma;"><small><span
style="font-weight: bold;"><br>
Add event code to main composite<br>
<br>
</span></small></div>
<div style="margin-left: 80px; font-family: tahoma;"><small>But how
will the dialog appear in the first place? We will add code to the main
composite's aboutButton event handler, so go back to the main composite
and add a SelectionListener.widgetSelected event handler for the
aboutButton. If you like, use a "handlerMethod" instead of "inline"
this time. Then add the following code to the event handler:<br>
<br>
</small><span style="font-family: monospace;"><span
style="font-weight: bold;">AboutDialog about = new
AboutDialog(getShell(), SWT.DIALOG_TRIM);</span><br
style="font-weight: bold;">
<span style="font-weight: bold;">about.open();</span><br>
<br>
</span><small><span style="font-family: tahoma;">Now, it would be nice
if the statusLabel's text were updated from the browser, so add a
StatusTextListener.changed event handler to the browser control (using
Jigloo's event editor, of course) and add a single line of code (shown
in bold text below) so the handler looks like this:</span></small><span
style="font-family: monospace;"><br>
<br>
browser1.addStatusTextListener(new StatusTextListener() {<br>
public void changed(StatusTextEvent evt) {<br>
<span
style="font-weight: bold;">statusLabel.setText(evt.text);</span><br>
}<br>
});<br>
<br>
</span><small><br style="font-family: tahoma;">
<span style="font-family: tahoma;">Now, we need to be able to send a
url to the browser, so we will add a method that will do that, and also
add the url to the addressCombo's list (if it is not already in it)<br>
<br>
</span></small><span style="font-family: monospace; font-weight: bold;">private
void go() {<br>
String url = addressCombo.getText();</span><br
style="font-weight: bold;">
<span style="font-family: monospace; font-weight: bold;">
if(addressCombo.indexOf(url) < 0)<br>
addressCombo.add(url);<br>
browser1.setUrl(url</span><span
style="font-family: monospace;"><span style="font-weight: bold;">);</span><br
style="font-weight: bold;">
<span style="font-weight: bold;">}</span><br>
<br>
</span><small><span style="font-family: tahoma;">Then we will add a
KeyListener.keyPressed handler to the addressCombo </span></small><small><span
style="font-family: tahoma;">(using Jigloo's event editor)</span></small><small><span
style="font-family: tahoma;">, so that when "Enter" is pressed the url
will be sent to the browser<br>
<br>
</span></small><span style="font-family: monospace;">addressCombo</span><span
style="font-family: monospace;">.addKeyListener(new KeyAdapter() {<br>
public void keyPressed(KeyEvent evt) {<br>
<span style="font-weight: bold;">if(evt.keyCode
== SWT.CR)</span><br style="font-weight: bold;">
<span style="font-weight: bold;">
go();</span><br>
}<br>
});<br>
<small><br>
</small></span><small><span style="font-family: tahoma;">And finally, a
simple SelectionListener.widgetSelected handler to the goButton</span></small><span
style="font-family: monospace;"><br>
<br>
goButton.addSelectionListener(new SelectionAdapter() {<br>
public void widgetSelected(SelectionEvent evt) {<br>
<span style="font-weight: bold;">go();</span><br>
}<br>
});<br>
<br>
<br>
</span></div>
<small><span style="font-weight: bold; font-family: tahoma;">Running
the app<br>
<br style="font-family: tahoma;">
</span></small>
<div style="margin-left: 40px; font-family: tahoma;"><small>Congratulations!
You are all done! Hit CTRL+S to save the form. A quick way to run the
main method of the class you
just created is to click the "Run" button in the Outline view.<br>
<img src="../swing_tutorial/run.png" title="" alt=""
style="width: 238px; height: 55px;"><br>
<br>
And here it is running...<br>
<br>
<img src="browser2.png" title="" alt=""
style="width: 606px; height: 401px;"><br>
<br>
</small><small> <br>
<br>
<br>
</small></div>
<p style="font-family: tahoma;"><small><br>
<br>
</small></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -