如何在RCP开发中能够弹出像Eclipse那样子的自动对话框吗?
展开全部
将下面这段代码加入到你的事件处理函数中即可:
new PopupDialog(button.getShell(), PopupDialog.HOVER_SHELLSTYLE,
true, false, false, false, false, null, null) {
private static final int CURSOR_SIZE = 15;
protected Point getInitialLocation(Point initialSize) { //弹出窗口的初始位置,此处为鼠标的位置
//show popup relative to cursor
Display display = getShell().getDisplay();
Point location = display.getCursorLocation();
location.x += CURSOR_SIZE;
location.y += CURSOR_SIZE;
return location;
}
protected Control createDialogArea(Composite parent) { //创建弹出窗口里的内容
Label label = new Label(parent, SWT.WRAP);
label.setText("Only for test");
label.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent event) {
close();
}
});
// Use the compact margins employed by PopupDialog.
GridData gd = new GridData(GridData.BEGINNING
| GridData.FILL_BOTH);
gd.horizontalIndent = PopupDialog.POPUP_HORIZONTALSPACING;
gd.verticalIndent = PopupDialog.POPUP_VERTICALSPACING;
label.setLayoutData(gd);
return label;
}
}.open();//打开对话框
你可以自己设置弹出窗口的内容布局,修改里面的函数就可以了。
new PopupDialog(button.getShell(), PopupDialog.HOVER_SHELLSTYLE,
true, false, false, false, false, null, null) {
private static final int CURSOR_SIZE = 15;
protected Point getInitialLocation(Point initialSize) { //弹出窗口的初始位置,此处为鼠标的位置
//show popup relative to cursor
Display display = getShell().getDisplay();
Point location = display.getCursorLocation();
location.x += CURSOR_SIZE;
location.y += CURSOR_SIZE;
return location;
}
protected Control createDialogArea(Composite parent) { //创建弹出窗口里的内容
Label label = new Label(parent, SWT.WRAP);
label.setText("Only for test");
label.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent event) {
close();
}
});
// Use the compact margins employed by PopupDialog.
GridData gd = new GridData(GridData.BEGINNING
| GridData.FILL_BOTH);
gd.horizontalIndent = PopupDialog.POPUP_HORIZONTALSPACING;
gd.verticalIndent = PopupDialog.POPUP_VERTICALSPACING;
label.setLayoutData(gd);
return label;
}
}.open();//打开对话框
你可以自己设置弹出窗口的内容布局,修改里面的函数就可以了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询