-
Notifications
You must be signed in to change notification settings - Fork 12
BalloonWindow
Haixing Hu edited this page Sep 26, 2014
·
6 revisions
A BalloonWindow
is a floating balloon window anchor to the corner of another control. It's something like the org.eclipse.swt.widgets.ToolTip
, except that
it could contain any controls instead of a simple messsage, and should not have to be attached with a org.eclipse.swt.widgets.TrayItem
.
This is the modified versino of the BalloonWindow
widget comes from the Novocode SWT Controls. It has been modified in the following way:
- Refactor the code to make the logic more clear.
- The new
BalloonWindow
could moves with its parent together. - Could set the anchor to
SWT.LEFT
,SWT.RIGHT
,SWT.TOP
, orSWT.BOTTOM
.
-
Add the shadow to the balloon window.(Is it possible?)
Here is the code snippet:
final Button button = new Button(shell, SWT.NONE);
button.setText("Click this button to show a balloon window.");
button.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
onClick();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
onClick();
}
public void onClick() {
System.err.println("Button clicked.");
// we should recompute the location of the label before show the balloon
// window
final BalloonWindow bw = createBalloonWindow(shell.getDisplay());
final Point loc = button.toDisplay(button.computeSize(SWT.DEFAULT, SWT.DEFAULT));
bw.setLocation(loc);
bw.open();
}
});
...
private static BalloonWindow createBalloonWindow(Display display) {
final int style = SWT.ON_TOP | SWT.TITLE | SWT.CLOSE;
final BalloonWindow bw = new BalloonWindow(display, style);
bw.setTitleText("This is the title text");
final Image img = SWTResourceManager.getImage(display,
BalloonWindowExample.class, "/images/warning.png");
bw.setTitleImage(img);
final Label label = new Label(bw.getContents(), SWT.WRAP);
label.setText("You can add any widgets to the contents composite of the "
+ "balloon window. You can add any widgets to the contents composite of the "
+ "balloon window. You can add any widgets to the contents composite of the "
+ "balloon window. You can add any widgets to the contents composite of the "
+ "balloon window. You can add any widgets to the contents composite of the "
+ "balloon window. ");
label.setSize(label.computeSize(300, SWT.DEFAULT));
label.setBackground(bw.getShell().getBackground());
bw.getContents().setSize(label.getSize());
bw.addSelectionControl(label);
bw.setAnchor(SWT.TOP | SWT.LEFT);
return bw;
}
An example is located in the source repository:
src/test/java/com/github/haixing_hu/swt/window/BalloonWindowExample.java