惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Apple Machine Learning Research
Apple Machine Learning Research
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
MyScale Blog
MyScale Blog
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium
阮一峰的网络日志
阮一峰的网络日志
博客园 - Franky
Recent Announcements
Recent Announcements
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
The GitHub Blog
The GitHub Blog
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - ols

grails导入excel grails的插件 grails环境搭建 短租app简析 在.net中用NAudio控件播放MP3 不小心发现中粮网站的一个bug 第十三章 第六节 本章小结 第十三章 第五节 关于WindowManager的一些话 第十三章 第四节 ApplicationWindow类 第十三章 第三节 SWT和JFace的关系 第十三章 第二节 问候JFace的世界 第十三章 第一节 概述 第四章 第五节 使用GridLayout 第四章 第四节 使用RowLayout 第四章 第三节 使用FillLayout 第四章 第二节 布局 第四章 第一节 概述 第三章 第七节 本章小结 第三章 第六节 SWT类的常量与函数
第三章 第五节 剖析Shell对象
ols · 2011-09-10 · via 博客园 - ols

第五节 剖析Shell对象

返回目录

Shell对象代表了一个窗口——要么是个顶级窗口,要么是个对话框。它容纳(contain)了各种各样的控件以构建应用程序:按钮、文本框、表格等等。它有六个构造函数,其中两个已不推荐使用,而且将来的发行版可能不再支持它们。构造过程沿用了SWT传递一个容器(parent)和一个样式(或者多个样式的位与or),有些构造函数允许单个或两个参数使用默认值。表3-3列出了构造函数。

3-3  Shell的构造函数

构造函数

说明

public Shell()

Empty constructor, which is equivalent to calling Shell((Display) null). Currently, passing null for the Display causes the Shell to be created on the active display, or, if no display is active, on a "default" display. This constructor is discouraged, and might be removed from a future SWT release.

public Shell(int style)

This constructor, too, isn't recommended for use, as it calls Shell((Display) null, style), so also might be removed from SWT.

public Shell(Display display)

Constructs a shell using display as the display, null for the parent, and SHELL_TRIM for the style, except on Windows CE, where it uses NONE (see Table 3-4).

public Shell(Display display, int style)

Constructs a shell using display as the display, null for the parent, and style for the style. See Table 3-4 for appropriate Shell styles.

public Shell(Shell parent)

Constructs a shell using the parent's Display as the display, parent for the parent, and DIALOG_TRIM for the style, except on Windows CE, where it uses NONE (see Table 3-4).

public Shell(Shell parent, int style)

Constructs a shell using the parent's Display as the display, parent for the parent, and style for the style. See Table 3-4 for appropriate Shell styles.

3-4: Shell的样式

样式(Style)

说明

BORDER

Adds a border.

CLOSE

Adds a close button.

MIN

Adds a minimize button.

MAX

Adds a maximize button.

NO_TRIM

Creates a Shell that has no border and can't be moved, closed, resized, minimized, or maximized. Not very useful, except perhaps for splash screens.

RESIZE

Adds a resizable border.

TITLE

Adds a title bar.

DIALOG_TRIM

Convenience style, equivalent to TITLE | CLOSE | BORDER.

SHELL_TRIM

Convenience style, equivalent to CLOSE | TITLE | MIN | MAX | RESIZE.

APPLICATION_MODAL

Creates a Shell that's modal to the application. Note that you should specify only one of APPLICATION_MODAL, PRIMARY_MODAL, SYSTEM_MODAL, or MODELESS; you can specify more, but only one is applied. The order of preference is SYSTEM_MODAL, APPLICATION_MODAL, PRIMARY_MODAL, then MODELESS.

PRIMARY_MODAL

Creates a primary modal Shell.

SYSTEM_MODAL

Creates a Shell that's modal system-wide.

MODELESS

Creates a modeless Shell.

所有的构造函数都调用包内可见的构造函数,用它设置display,样式、容器(parent),然后创建窗体。如果Shell有容器(parent),它就是一个对话框;否则,它就是顶级窗口。表3-4列出了Shell对象可能的样式;注意,我们将在下一节看到,所有的样式常量,都是SWT类的静态(static)成员。同时,也要注意设置的样式仅仅被作为提示(hint)被对待,当程序允许的平台上不支持这种样式时,它会被忽略。

大多数时候,创建Shell时不需要指出样式,因为默认的设置通常就是客户想要的。自己试验下各种样式,这样就可以了解它们。

Shell从它的继承树中继承了大量的方法,并且添加了一些自己的方法(Shell特有的全部方法列表请参见表3-5)。但是经常用到的两个方法是open()close(),其中open()打开(显示)Shellclose()关闭Shell。注意,默认的操作平台已经实现了关闭Shell的方法(例如,单击标题栏的关闭按钮),所以程序员可能从来都不用调用close()

3-5: Shell 的方法

方法

说明

void addShellListener (ShellListener listener)

Adds a listener that's notified when operations are performed on the Shell.

void close()

Closes the Shell.

void dispose()

Disposes the Shell, and recursively disposes all its children.

void forceActive()

Moves the Shell to the top of the z-order on its Display and forces the window manager to make it active.

Rectangle getBounds()

Returns the Shell's size and location relative to its parent (or its Display in the case of a top-level Shell).

Display getDisplay()

Returns the Display this Shell was created on.

boolean getEnabled()

Returns true if this Shell is enabled, and false if not.

int getImeInputMode()

Returns this Shell's input-method editor mode, which is the result of bitwise ORing one or more of SWT.NONE, SWT.ROMAN, SWT.DBCS, SWT.PHONETIC, SWT.NATIVE, and SWT.ALPHA.

Point getLocation()

Returns the location of this Shell relative to its parent (or its Display in the case of a top-level Shell).

Region getRegion()

Returns this Shell's region if it's nonrectangular. Otherwise, returns null.

Shell getShell()

Returns a reference to itself.

Shell[] getShells()

Returns all the Shells that are descendants of this Shell.

Point getSize()

Returns this Shell's size.

boolean isEnabled()

See getEnabled().

void open()

Opens (displays) this Shell.

void removeShellListener (ShellListener listener)

Removes the specified listener from the notification list.

void setActive()

Moves the Shell to the top of the z-order on its Display and asks the window manager to make it active.

void setEnabled(boolean enabled)

Passing true enables this Shell; passing false disables it.

void setImeInputMode (int mode)

Sets this Shell's input-method editor mode, which should be the result of bitwise ORing one or more of SWT.NONE, SWT.ROMAN, SWT.DBCS, SWT.PHONETIC, SWT.NATIVE, and SWT.ALPHA.

void setRegion(Region region)

Sets the region for this Shell. Use for nonrectangular windows.

void setVisible(boolean visible)

Passing true sets this Shell visible; passing false sets it invisible.

返回目录