Java 在屏幕上SWT的顶部外壳上隐藏最小化

Java 在屏幕上SWT的顶部外壳上隐藏最小化,java,swt,Java,Swt,我试图在最小化显示时隐藏SWT外壳。我错过了一些东西,非常感谢你的帮助 附加信息:这个shell实际上是一个弹出窗口,当用户单击一个组合时会被绘制出来。最后,我的目标是在组合不可见时隐藏这个弹出shell(用户最小化窗口或在窗口之间切换,例如使用Alt+Tab) 这是我的密码: static Shell middleClickNodeInfoShell ; static Label nodeIdLabel ; void init(){ ... /** Focused node

我试图在最小化显示时隐藏SWT外壳。我错过了一些东西,非常感谢你的帮助

附加信息:这个shell实际上是一个弹出窗口,当用户单击一个组合时会被绘制出来。最后,我的目标是在组合不可见时隐藏这个弹出shell(用户最小化窗口或在窗口之间切换,例如使用Alt+Tab)

这是我的密码:

static Shell middleClickNodeInfoShell ;
static Label nodeIdLabel ;

void init(){
    ... 
    /** Focused node on middle click*/
    middleClickNodeInfoShell = new Shell(Display.getDefault(), SWT.BORDER | SWT.MODELESS);
    middleClickNodeInfoShell.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
    middleClickNodeInfoShell.setLayout(createNoMarginLayout(1, false));

    nodeIdLabel = new Label(middleClickNodeInfoShell, SWT.NONE);
    Display.getDefault().addListener(SWT.Iconify,new Listener() {
        @Override
        public void handleEvent(Event arg0) {
            // TODO Auto-generated method stub
            middleClickNodeInfoShell.setVisible(false);
        }
    });
}   

@Override
public boolean onMouseClicked(Button button, ScreenPosition screenPos,
            final GeoPosition arg2) {
    ... 

    nodeIdLabel.setText("Node Id: "+node.getId());
    middleClickNodeInfoShell.setLocation(pos.getX()+displayX,pos.getY()+displayY+30);
    middleClickNodeInfoShell.setVisible(true);
    middleClickNodeInfoShell.pack();
}

下面是示例代码,它将帮助您确定您要查找的内容

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setSize(300, 200);
    shell.setText("Shell Example");
    shell.setLayout(new RowLayout());

    final Button button = new Button(shell, SWT.PUSH);
    button.setText("Click Me");


    final Shell tip = new Shell(shell,SWT.MODELESS);
    tip.setLayout(new FillLayout());
    Label lbl = new Label(tip, SWT.NONE);
    lbl.setText("***tooltip***");
    tip.pack();
    shell.addControlListener(new ControlListener() {
      @Override
      public void controlResized(ControlEvent e) {
        changeTipLocation(display, button, tip);
      }
      @Override
      public void controlMoved(ControlEvent e) {
        changeTipLocation(display, button, tip);
      }
    });

    button.addSelectionListener(new SelectionAdapter() {

      public void widgetSelected(SelectionEvent event) {
        changeTipLocation(display, button, tip);
        tip.open();
      }

    });
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();

  }

  private static void changeTipLocation(final Display display, final Button button, final Shell tip) {

    Rectangle bounds = button.getBounds();
    Point loc = button.getLocation();
    tip.setLocation(display.map(button, null, new Point(loc.x+bounds.width, loc.y+bounds.height)));
  }

我猜这不是完整的代码,发布完整的代码并为postHey Chandrayya添加更多细节,我添加了更多代码。干杯。此代码将不会在其他用户的计算机上编译,因为它不完整。添加更多的代码,以便我们直接复制您的代码并测试、验证和修复问题。此代码是OSGI环境的一部分,具有专有捆绑包。我剥去了衣服的右边部分。使用原始代码也无法编译。除非合适,否则请避免使用caps lock。问题很简单:当鼠标位于可见组合上时显示一个弹出窗口,当组合不再可见时隐藏它。我认为你必须注意的不仅仅是图标化事件,如果通过滚动组合不可见怎么办。您的代码可能会导致内存泄漏,因为您正在将侦听器添加到显示器中,并且在处理复合文件时不会删除它。