gpt4 book ai didi

java - 在显示最小化的 SWT 中隐藏 ON_TOP shell

转载 作者:行者123 更新时间:2023-11-30 11:21:08 26 4
gpt4 key购买 nike

我试图在显示最小化时隐藏 SWT 外壳。我遗漏了一些东西,非常感谢任何帮助。

附加信息:这个 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)));
}

关于java - 在显示最小化的 SWT 中隐藏 ON_TOP shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22382591/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com