index.html
来自「eclipse插件jigloo」· HTML 代码 · 共 485 行 · 第 1/2 页
HTML
485 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="CONTENT-TYPE"
content="text/html; charset=windows-1252">
<title>Jigloo Swing Tutorial</title>
<meta name="GENERATOR" content="OpenOffice.org 2.0 (Win32)">
<meta name="AUTHOR" content="Cloudgarden.com">
<meta name="CREATED" content="20051126;10023565">
<meta name="CHANGED" content="16010101;0">
<style>
<!--
TD P { margin-top: 0.1in; margin-bottom: 0.1in; color: #000000; font-family: "Arial", "Helvetica", sans-serif; font-size: 10pt }
P { margin-top: 0.1in; margin-bottom: 0.1in; color: #000000; font-family: "Arial", "Helvetica", sans-serif; font-size: 10pt }
H3 { font-size: 11pt }
A:link { color: #0000ff }
-->
</style>
<meta name="author" content="Jonathan Kinnersley">
</head>
<body bgcolor="#ffffff" dir="ltr" lang="en-US" link="#0000ff">
<h4 style="font-family: tahoma;"><small>Jigloo Swing Tutorial</small></h4>
<small><font face="Helvetica, Arial, sans-serif"
style="font-family: tahoma;">In this simple tutorial you will create a
small application with an "About" dialog, a menu bar, and the code to
open and close the dialog. You will use the swing's GroupLayout to
arrange the elements on both JFrame and JDialog, and swing Actions to
control the JDialog.<br>
<br>
<span style="font-weight: bold;">Topics covered:</span><br>
</font></small>
<ul style="font-family: tahoma;">
<li><small>Arranging elements using GroupLayout - anchoring and
expanding by positioning or resizing or by using the drop-down menu<br>
</small></li>
<li><small>Adding Actions to menu items and buttons - and associating
accelerators and mnemonics with actions<br>
</small></li>
<li><small>Navigating between visual elements in the tree outline and
their code</small></li>
<li><small>Adding multiple </small><small>elements </small><small>
</small><small>of the same type to a form<br>
</small></li>
<li><small>Multi-selecting </small><small>elements </small></li>
<li><small>"Surround by" action - useful for times when you realise
you really need your table to be in a scroll pane, etc</small></li>
<li><small>Designing multple "root" visual elements in the same form
- in this case a JFrame and a JDialog</small></li>
<li><small>Changing which properties appear under the "Basic" and
"Expert" headings in the "GUI Properties" editor.</small></li>
</ul>
<small><font face="Helvetica, Arial, sans-serif"
style="font-family: tahoma;"><br>
First you will need a Java project and (preferably) a package to hold
your classes. <br>
If you don't know how to do this then hitting <span
style="font-weight: bold;">Ctrl+N</span> is a quick way to bring up
the "Create" dialog from which you can perform both these steps.<br>
<br>
<span style="font-weight: bold;">Creating the main JFrame<br>
<br>
</span></font></small>
<div style="margin-left: 40px; font-family: tahoma;"><small><span
style="font-weight: bold;">Create new JFrame</span><br>
</small>
<div style="margin-left: 40px;"><small>...again, Ctrl+N will show the
"create" dialog, from which you should select "GUI
forms->Swing->JFrame"<br>
<br>
<img src="new_frame.png" title="" alt=""
style="width: 617px; height: 498px;"><br>
<br>
</small></div>
<small><span style="font-weight: bold;">Choose your editor preferences<br>
</span></small>
<div style="margin-left: 40px;"><small>Now we've got a Jigloo editor
open, let's change how it looks. Click on the "Open Jigloo preferences
editor" button in the toolbar to the left of the Jigloo editor. The
Eclipse preferences window appears with Jigloo selected. Choose
"Appearance and Behaviour" and then "Tabbed panels". This is useful
when you want to maximize your design area, but "Split-pane" can be
useful if you want to see immediately the connection between code and
GUI. <br>
<img src="prefs.png" title="" alt=""
style="width: 715px; height: 572px;"><br>
<br>
Now hit "OK" and close and re-open the Jigloo editor (you need to
do this to change to tabbed panels). If your java class does not
immediately re-open in the Jigloo editor, you can ensure that it uses
Jigloo's Form Editor by right-clicking on the class and choosing "Open
with->Form editor".<br>
<br>
<img src="open_jigloo.png" title="" alt=""
style="width: 518px; height: 314px;"><br>
</small><br>
</div>
<small><span style="font-weight: bold;">Maximize Jigloo<br>
</span></small>
<div style="margin-left: 40px;"><small>You will probably find it easier
to design a GUI if you can see as much of it as possible, so
double-click on the editor tab and the Jigloo editor will</small><small>
take over most of Eclipse and arrange itself so you can see an outline
of the elements, the property editor and the form designer.<br>
<br>
<img src="maxed.png" title="" alt=""
style="width: 787px; height: 615px;"><br>
</small></div>
<small><span style="font-weight: bold;"><br>
Set layout to GroupLayout</span><br>
</small>
<div style="margin-left: 40px;"><small>You can either select the
GroupLayout icon in the "layout" palette, or right-click on the JFrame
and select "Set Layout->GroupLayout"<br>
<br>
<img src="set_layout.png" title="" alt=""
style="width: 456px; height: 460px;"><br>
If you are using Java 6 then code will be generated for the
javax.swing.GroupLayout which is part of Java 6. <br>
If you are not using Java 6, Jigloo will use the
org.jdesktop.layout.GroupLayout (which is the equivalent of the swing
GroupLayout) and will let you know that it needs to add the
swing-layout-1.0.jar file to your project.<br>
<br>
<img src="add_lib.png" title="" alt=""
style="width: 440px; height: 158px;"><br>
<br style="font-weight: bold;">
</small></div>
<small><span style="font-weight: bold;">Add OK and Cancel buttons</span><br>
</small>
<div style="margin-left: 40px;"><small>Select the JButton icon from the
"Components" palette and move the cursor down to the bottom-right of
the form until it "clicks" into place. <br>
<img src="bottom_right_button.png" title="" alt=""
style="width: 105px; height: 60px;"><br>
In the dialog that will open (if you have selected that option in the
jigloo preferences) you will be able to set the button's name and text
(and icon if you want). You can also do all this later.</small><small>
We will make this the "Cancel" button.</small><br>
<small><img src="cancel_button_dlg.png" title="" alt=""
style="width: 457px; height: 389px;"><br>
Then hold CTRL and SHIFT down and you will be able to add another
button without returning to the component palette.<br>
<img src="two_butts.png" title="" alt=""
style="width: 159px; height: 54px;"><br>
<br>
If you aligned the buttons with the bottom-right of the form
you should see (as in the image above) a faint red arrow connecting the
buttons to the right of
the form and a blue arrow connecting them to the bottom of the form,
indicating that they are anchored to those sides of the form. <br>
<br>
You can
also change the anchoring by either re-positioning the buttons next to
edges
of the form, or by using the drop-down alignment menu which you can
access from the
"arrow" button on the top-right of the element. Note all
the menu options, which allow you to change how the element behaves as
the form is resized.<br>
<img src="alignment.png" title="" alt=""
style="width: 299px; height: 156px;"><br>
<br>
</small><small>
Label the buttons "OK" and "Cancel" - you can double-click on the
button to edit the label, or edit the "text" property.<br>
<img
src="file:///C:/workspace-jigloo/jigloo/html/swing_tutorial/edit_txt_1.png"
title="" alt="" style="width: 82px; height: 50px;">
<img
src="file:///C:/workspace-jigloo/jigloo/html/swing_tutorial/edit_txt_2.png"
title="" alt="" style="width: 82px; height: 50px;"><br>
<br>
</small></div>
<small><span style="font-weight: bold;">Make OK and Cancel buttons same
width, and same font</span><br>
</small>
<div style="margin-left: 40px;"><small>Multi-select the OK and Cancel
buttons - you can do this using either:<br>
</small>
<ul>
<li><small>the "rubber band" technique - hold SHIFT down then drag
the mouse over both buttons, then release the mouse, or<img
src="rubber_band.png" title="" alt=""
style="width: 152px; height: 61px;" align="top"></small></li>
<li><small>holding CTRL down as you click on the buttons</small></li>
</ul>
<small>Click on the "Make selected elements the same width" icon in the
alignment toolbar. <br>
<img src="link_widths.png" title="" alt=""
style="width: 458px; height: 165px;"><br>
Then select the OK button - notice that now the "same widths" icon has
changed to "Unlink the selected element's width from all other
elements". This allows you to "unlink" an individual element after it
has been linked.<br>
<br>
Now multi-select both buttons again and (just for fun) change
the font to "bold" by clicking on the "font" property in the "GUI
Properties" view and using the dialog that will appear after you click
on the small "..." button.<br>
<img src="edit_font.png" title="" alt=""
style="width: 599px; height: 389px;"><br>
<br>
</small></div>
<small><span style="font-weight: bold;">Add JTable</span><br>
</small>
<div style="margin-left: 40px;"><small>using the "Components" palette -
add it to the top-left of the form.<br>
<br>
</small></div>
<small><span style="font-weight: bold;">Surround by JScrollPane and
stretch it across the form.</span><br>
</small>
<div style="margin-left: 40px;"><small>Oops - you just remembered you
really meant to add a JScrollPane first, for the table to go inside,
but instead of undoing what you did, you can right-click on the JTabel
and choose "Surround by->JScrollPane".<br>
<br>
<img src="surround_by.png" title="" alt=""
style="width: 529px; height: 168px;"><br>
<br>
Now select the JScrollPane (either in the outline or by clicking on
it's scrollbars, or it's edges - if a scrollpane's child element
occupies all of the area of a scrollpane and there are no scrollbars,
clicking near the edge of the scrollpane will select the scrollpane).
Then drag the side or corner of the JScrollPane so that it stretches
from the
left to the right of the form and is a bit taller. Again, red and blue
arrows should
indicate that it is connected to both the left and right sides of the
form. <br>
<br>
If you open the drop-down menu you will see that "Expands Horizontally"
is checked, and as before you can use that menu to change any of the
listed properties. Note that you will need to uncheck "Expands
horizontally" in order to be able to anchor it left or right.<br>
<br>
</small></div>
<small><span style="font-weight: bold;">Add two JTextField (using
quick-repeat) and JButton<br>
<br>
</span></small>
<div style="margin-left: 40px;"><small>Just to get a feel for
GroupLayout, add two JTextFields and a JButton, then select them all
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?