【发布时间】:2014-11-16 10:33:26
【问题描述】:
我正在使用这个PopupComposite,我想知道如何打开一个包含按钮的弹出式外壳(pc1),该按钮会打开另一个弹出式外壳(pc2),而无需关闭第一个弹出式外壳。我尝试修改 PopupComposite 的激活侦听器,但我得到的只是一个解决方案,每次打开 pc2 时都会闪烁 pc1。我在 shellActivated 中添加了以下代码:
if(shell.getParent() != null)
shell.getParent().setVisible(true);
每当弹出窗口失去焦点时,它们必须隐藏(我不能将 FocusListener 用于 shell,因为它在 mac 上不起作用)。
这是我的测试仪:
public class TestShells
{
public static void main(final String[] args)
{
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));
final Composite container = new Composite(shell, SWT.NULL);
container.setLayout(new FillLayout());
final Button btn = new Button(container, SWT.PUSH);
btn.setText("Button 1");
final PopupComposite pc1 = new PopupComposite(Display.getDefault().getActiveShell(), SWT.NULL);
final Button btn2 = new Button(pc1, SWT.PUSH);
btn2.setText("Button 2");
final PopupComposite pc2 = new PopupComposite(pc1.getShell(),SWT.NULL);
final Text text = new Text(pc2, SWT.BORDER);
btn.addSelectionListener(new SelectionListener()
{
public void widgetSelected(final SelectionEvent e)
{
pc1.show(btn.getLocation());
}
public void widgetDefaultSelected(final SelectionEvent e)
{
}
});
btn2.addSelectionListener(new SelectionListener()
{
public void widgetSelected(final SelectionEvent e)
{
pc2.show(btn2.getLocation());
}
public void widgetDefaultSelected(final SelectionEvent e)
{
// TODO Auto-generated method stub
}
});
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
非常感谢!
【问题讨论】:
标签: java shell swt eclipse-rcp jface