Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何打开弹出shell而不关闭上一个shell_Java_Shell_Swt_Eclipse Rcp_Jface - Fatal编程技术网

Java 如何打开弹出shell而不关闭上一个shell

Java 如何打开弹出shell而不关闭上一个shell,java,shell,swt,eclipse-rcp,jface,Java,Shell,Swt,Eclipse Rcp,Jface,我正在使用它,我想知道如何打开一个包含按钮的弹出外壳(pc1),它打开另一个弹出外壳(pc2),而不关闭第一个弹出外壳。我试图修改PopupComposite的激活侦听器,但我得到的解决方案是每次打开pc2时都会闪烁pc1。我在shellActivated中添加了以下代码: if(shell.getParent() != null) shell.getParent().setVisible(true); 每当弹出窗口失去焦点时,它们都必须隐藏(我不能将FocusList

我正在使用它,我想知道如何打开一个包含按钮的弹出外壳(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();
    }
}

多谢各位

我不知道如何隐藏上一个窗口,但作为Windows用户,我也可以告诉您,在一堆程序下面出现弹出式窗口消失通常令人沮丧,因此我建议不要这样做

至于实际问题:您是否尝试过
JDialog
?只需在按下按钮时显示的对话框窗口中堆叠一个
JOptionPane

编辑:这是应该可以工作的代码片段,我还没有测试过它

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

public class Snippet99 {

  public static void main(String[] args) 
  {
    final private Display display = new Display();
    final private Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(1, false));

    final Composite container = new Composite(shell, SWT.NULL);
        container.setLayout(new FillLayout());

    final private Button btn = 
new Button(container, SWT.PUSH).setText("Button 1");
    final private PopupComposite pc1 = 
new  PopupComposite(Display.getDefault().getActiveShell(), SWT.NULL);
    final private Button btn2 = 
new Button(pc1, SWT.PUSH).setText("Button 2");
    final private PopupComposite pc2 = 

new PopupComposite(pc1.getShell(),SWT.NULL);

    private Text text = new Text(pc2, SWT.BORDER);
    /*
    only use final if you're setting the value immediately and will never change it again,
    make sure you set the accessibility of your items (protected/private/public)
    */

    Listener listener = new Listener() {
      public void handleEvent(Event event) {
        pc1.show(btn.getLocation());
      }
    };

    btn.addListener(SWT.Selection, listener);

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

谢谢您的建议,但我只允许使用SWT。@JNewbie更改很重要。在这种情况下,看看这个修改关闭行为的示例:已经尝试过了,但是我的条件在那一点上无法验证,因为我接下来要打开的外壳只有在这个外壳关闭后才会打开。为什么你在第一篇帖子中说你想让它们都打开?然后我的评论就站起来了,您应该看看他的示例,将第二个屏幕的逻辑添加到他给出确认对话框的位置,并修改actionlistener,以便在您按下按钮时显示这个新的弹出窗口,而不是关闭屏幕1。