我正在开发一个rcp应用程序。我正在使用Novocode swt气球窗口。我需要在按钮点击时显示一个BaloonWindow。但每当我点击按钮每次创建一个新的气球窗口
我的代码在
下面public Object execute(ExecutionEvent event) throws ExecutionException {
try {
BalloonWindow baloonWindow=new BalloonWindow(HandlerUtil.getActiveWorkbenchWindow(event).getShell(),SWT.ON_TOP|SWT.TOOL|SWT.CLOSE);
baloonWindow.setText("XYZ");
baloonWindow.setAnchor(SWT.RIGHT|SWT.TOP);
baloonWindow.setLocation(1290, 90);
Composite c = baloonWindow.getContents();
String array[]=new String[2];
array[0]="A";
array[1]="B";
c.setLayout(new FillLayout());
TableViewer t=new TableViewer(c,SWT.NONE);
t.setContentProvider(new ArrayContentProvider());
t.setInput(array);
c.pack(true);
baloonWindow.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
任何人都可以帮助我。如果时间只显示一个气球窗口。如果气球窗口打开,则不允许打开另一个气球窗口,或者在任何给定的时间点应该只保留一个气球窗口。
答案 0 :(得分:0)
我不太确定我理解你的最终目标,所以这里有两种可能性:
首先(一次最多一个BalloonWindow
)
在您的班级中创建包含static
方法的boolean
isOpen
字段execute()
。创建true
后,将此变量设置为BalloonWindow
,并在每次输入execute()
时检查此变量。如果是false
,请创建新的BalloonWindow
,如果是true
,return
。
第二次(关闭BalloonWindow
)
BalloonWindow
有方法open()
。使用此方法打开它而不是setVisible(true)
。如果您要关闭BalloonWindow
,只需致电close()
即可。 setVisible(false)
会有相同的视觉效果(窗口消失了),但它仍然存在(只有不可见)。 close
真的关闭了窗口。