Initial experience Widget for the Swt/jface introductory guide

Source: Internet
Author: User

Starting with widgets and control

The widget is the parent of control, and control is the parent of most of the parts we use. We may have been exposed to concepts such as "control" or "component" in some of the previous programming languages, and the concept of widgets is roughly the same as these.

Many widgets are defined in the org.eclipse.swt.widgets, and even the shell we described earlier is treated as a widget.

Because there are so many widgets available, I probably have no way to introduce them all. In this section, I'll introduce a few common widgets. Believe that you are good at analogy through these very brief introduction should be able to start using a variety of widgets, in the use of constantly improve their understanding.

First we'll introduce the widget. It is an abstract class and is also the parent of all widgets. By introducing this class, we can draw some common features of all the widgets.

Widget method in the Dispose () method we have seen before, call this method, the so-called receiver (receiver, such as we write: Awidget.dispose (), then Awidget is the receiver, The object in question becomes the caller or caller, and other widgets contained in the receiver release the resources of the underlying operating system that they occupy. This means that you don't have to explicitly dispose () of every widget you create in your program, but just make sure that the outermost widget (such as display) is Dispose ().

You can also determine whether the widget (recipient) has been dispose by isdisposed ().

The GetStyle () method in the widget gets the widget style, and the Getdisplay () Gets the display object in place.

There are also two important methods in the widget GetData () and SetData (), which allow us to attach additional information to a widget. This feature is especially useful when you need to pass widgets across modules. For example, if a text box shows a sentence in a passage, if we also want to add the title of the whole article and the author, we can write this:

1public class Labels ...{
2
3 public static void main(String[] args) ...{
4 Display display = new Display();
5 Shell shell = new Shell(display,SWT.SHELL_TRIM);
6 RowLayout layout=new RowLayout(SWT.VERTICAL);
7 shell.setLayout(layout);
8 shell.setText("Labels");
9 Label label1=new Label(shell,SWT.CENTER);
10 label1.setText("Label Demo");
11 Label label2=new Label(shell,SWT.SEPARATOR | SWT.HORIZONTAL);
12 shell.setSize(100,100);
13 shell.open();
14
15 while (!shell.isDisposed()) ...{
16 if (!display.readAndDispatch()) ... {
17 display.sleep();
18 }
19 }
20 display.dispose();
21 }
22}
23

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.