There are a number of style bits that are applicable to windows, and some useful methods to affect how the window appears. For example, it might be desirable to make the clock appear semi-transparent, which allows the clock to float above other windows. SWT's Shell
has a number of these options that can be set.
Shell
inside the widgetSelected
method in the Activator
inner class to add SWT.NO_TRIM
(no close/minimise/maximise widgets
) and SWT.ON_TOP
(floating on top of other windows):shell = new Shell(trayItem.getDisplay(), SWT.NO_TRIM | SWT.ON_TOP);
alpha
value as 128
, which is semi-transparent:shell.setAlpha(128);
tray
item to see what kind of window is created.SWT.APPLICATION_MODAL
:shell = new Shell(trayItem.getDisplay(), SWT.APPLICATION_MODAL);
setFullScreen
or the setMaximized
depending on the platform:shell.setFullScreen(true); shell.setMaximized(true);
Shell
back to use SWT.NO_TRIM
and SWT.ON_TOP
.Activator
class, which has been taken from SWT's Snippet134.java
, from http://www.eclipse.org/swt/snippets/:private static int[] circle(int r, int offsetX, int offsetY) { int[] polygon = new int[8 * r + 4]; // x^2 + y^2 = r^2 for (int i = 0; i < 2 * r + 1; i++) { int x = i – r; int y = (int)Math.sqrt(r*r – x*x); polygon[2*i] = offsetX + x; polygon[2*i+1] = offsetY + y; polygon[8*r - 2*i - 2] = offsetX + x; polygon[8*r - 2*i - 1] = offsetY – y; } return polygon; }
Region
of the Shell
. This will have the effect of making it look as if the clock itself is floating. Add the following code after the Shell
is created in the widgetSelected
method:final Region region = new Region(); region.add(circle(25, 25, 25)); shell.setRegion(region);
dispose
listener on the shell to ensure that the Region
is cleaned up:shell.addDisposeListener(event -> region.dispose());
Changing the flags affects how that window is displayed and interacts with the user. Other calls on the shell can programmatically drive transitions to full-screen and maximized or minimized status, which can be useful in specific circumstances. Some windowing systems do not differentiate maximized and full-screen; others have distinct properties.
The SWT.NO_TRIM
flag is used to display a window without the normal window furniture. This can be combined with setting a region via setRegion
, which allows creation of a non-rectangular shape.
Often, windows without trim are floating—that is, they stay on top of the application window even when it hasn't got the focus. To achieve this, set the SWT.ON_TOP
flag as well, and adjust the alpha (transparency) value with setAlpha
. The alpha
value is between 0
(fully transparent) and 255
(fully opaque).
A Region
can be defined from a set of connected points, or set on a pixel-by-pixel basis. It's important to note that a Region
is also a Resource
, and thus it must be disposed
after use (which is typically when the Shell
is closed). The cleanup operation is similar to that of the others previously mentioned, via the addDisposeListener
on the Shell
.
3.141.197.93