Use jigloo to develop swing

Source: Internet
Author: User

At present, the best interface designer developed by swing interface is the interface designer of netbeans, And there is basically no need to consider the layout issue.

Readers who want to have a deep understanding of how to use jigloo can readJigloo Gui
Builder Guide

This section describes more techniques, such as how to use jigloo in large file mode and how to avoid parsing some code.
How to parse the interface code and open the interface files created by other interface designers. These help documents can be opened through the help-> help contents menu.

1. Build a Development Environment

1. Download and install JDK/JRE

JDK can be from http://java.sun.com/j2se/

Download and install the SDK.
JDK can be used to develop and run swing.

2. Download and install jigloo

Jigloo

Can identify the guis created by most formbuilder, such as JBuilder
You can edit the AWT and swing/SWT interfaces. for personal use, free of charge for commercial use.

Note: jigloo is free for non-commercial cial use, but purchase of a professional
License is required for your cial use (after successfully evaluating
Jigloo ).

Note: In version 3.95, the eclipse versions tested and run by the author are 2.1, 3.2, and 3.3. For ease of illustration, the eclipse version used in this article is
3.3.0, jigloo 3.95, JDK 1.5.

Eclipse:

3.0. *, 3.1 *, 3.2 *, 3.3

Java:

1.3, 1.4 or 5.0

Platforms:

Windows, Linux (GTK) and Mac OSX. (on a Mac, only SWT guis can be built ).

: Jigloo_395.zip

Ii. simple use of jigloo

1. First knowledge of jigloo

First, we need to create a Java project named jiglooswing as shown above:

Choose File> New> project..., select Java project in the first category, and click Next,
Enter jiglooswing and click "F ".

Inish "button. Copy the following code to the clipboard and right-click the src directory of myproject,
Select "Paste" so that the conversion class appears in the project:

public class Converter {

public static String doConvert(String input) {

return input + " is converted.";

}

}

Choose File> New> other... and open the classification GUI forms> in the new dialog box.
Swing: Select jframe, as shown in:

In the following wizard dialog box, keep the default input value unchanged, and then delete the SRC package name:

 

Then, the new file is automatically opened with the jigloo interface designer, as shown below:

 

The Outline (outline) page displays the following content:

(1) click the button to switch whether to display the grid;

(2)
Click to pop up a window to preview the current design interface (not compiled );

(3) click the button to compile and run the generated code;

(4)
Click to start/stop the analysis code changes (the design interface is generated by the Code );

(5) Whether to display inherited components during button switching;

(6) switch the button from SWT to swing
Or reverse conversion (note that there will be code errors, which is not 100% accurate );

(7) list the Component Hierarchy outlines on the interface,
Click to select the corresponding component.

The following content is displayed on the editor page:

(8) UI being designed. Click handle and drag to adjust the widget size,
Location;

(9) Select the SWT/swing component panel, click a component, and then click (8) to place the component on the interface,
You can also continue to adjust the size and position;

(12) The Code view is displayed. This is the generated code. You can also modify the code below. After that, the interface in the design will be resolved again;

In
The GUI properties page displays the following content:

(10)
The button switching property list is displayed as sashform or tabbedpane );

(11) attribute list, in sequence: properties ),
Layout and event ).

2. Drag and Drop quick build Interface

Drag and Drop to preview.

First, selectThis-jframe, border

And then select layout in (11 ).
Panel, click the tree node layout (*), and select its value as absolute (absolute layout) in the drop-down list box on the right ).

We chose this layout mainly for the rapid development of the relationship, although this is not a good choice. For details, you can view relevant information about swing development on your own.

Okay,
Next, select the Panel components in (9), click the jtextfield control twice, and place it on the design panel. Drag it so that it does not overlap and place it in a proper position,
The two components can be jtextfield1 and jtextfield2.

Finally, we add a jbutton and modify the text value to OK in the Add dialog box.

Drag and Drop each component to fit the layout, as shown in:

 

At this time, you can click the toolbar button (2) or (3) to preview the designed interface. jigloo has helped you write most of the code, so you don't have to worry about the interface being unable to be displayed.

3. Add the Event Response Code

Click the "OK" button on the page, select the event panel in (11), expand actionlistener, and click
The not handled drop-down box on the right of the actionshortmed node, and then select handler method. This will generate a click OK
As shown in:

Then, the mouse in the editor locates the generated event method. The default generated code is as follows:

private void jButton1ActionPerformed(ActionEvent evt) {

System.out.println("jButton1.actionPerformed, event=" + evt);

//TODO add your code for jButton1.actionPerformed

}

We can add the following code after todo to complete the required functions:

Jtextfield2.settext (converter. doconvert (jtextfield1.gettext ()));

This Code sets the text content in text box 2 as the content processed by the previous conversion code. The input content is the text displayed in jtextfield1.
It is equivalent to calling the following code:

String input = jtextfield1.gettext ();

String output =
Converter. doconvert (input );

Jtextfield2.settext (output );

The settext (string) and gettext () Methods read and write the text displayed by the component.

4. Test

Click (3), run, modify the value in jtextfield1, and click OK. The running result is normal, as shown in:

 

3. Package and publish applications

1. Directory layout and copy dependent files

Our project does not rely on any third-party packages. The final file directory structure is shown below:

Jiglooswing

Category-classes

└ ── SRC

2. Write the Startup Script

Write and run. bat in the root directory. The content is as follows:

java -cp classes NewJFrame

Double-click the batch file to view the main window.

Iv. FAQs

 

Some common minor problems.

Q: After I edited the following code, I found that the GUI properties panel and the Component Hierarchy outline disappeared?

A: click the button in the interface designer and the GUI properties panel will appear again.

Q: What should I do if I want to set a title for the window and set the default value to NULL for the two text boxes?

A: Modify the text in the properties attribute. You can select a component in the interface designer and modify the component on the GUI attribute page. The main window is slightly more complex,
As shown in, you must first select jframe and then modify it:

 

Q: I want to use a multi-Line Text Editor (textarea). The example in this article is a single-line text box. What should I do?

A: change this operation to "next select panel components in (9), and then click twiceJtextarea

Control,
Put it on the design panel, drag it so that it does not overlap and place it in the appropriate position, the two components can follow the default value, respectively, jtextarea1, jtextarea2. if you find that put
Jtextarea2 cannot be added. Put it in the outline (7)This-jframe, absolute

You can ".

At the same time, the event processing code is changed to the following code based on the variable name:

Jtextarea2.settext (converter. doconvert (jtextarea1.gettext ()));

Q: I found that the jigloo interface designer was not displayed when I disabled eclipse and opened the code just now. How can I open it for editing?

A: Sometimes eclipse cannot remember the editor used when a file was opened last time. Therefore, make sure that this class is not opened by other eclipse editors,
Right-click the file and choose "open with-> form Editor", as shown in:

From: http://hi.baidu.com/dburu/blog/item/6404321f943f87c2a686692d.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.