• <legend id='q8PKo'><style id='q8PKo'><dir id='q8PKo'><q id='q8PKo'></q></dir></style></legend>
  • <small id='q8PKo'></small><noframes id='q8PKo'>

      <bdo id='q8PKo'></bdo><ul id='q8PKo'></ul>

      <tfoot id='q8PKo'></tfoot>

        <i id='q8PKo'><tr id='q8PKo'><dt id='q8PKo'><q id='q8PKo'><span id='q8PKo'><b id='q8PKo'><form id='q8PKo'><ins id='q8PKo'></ins><ul id='q8PKo'></ul><sub id='q8PKo'></sub></form><legend id='q8PKo'></legend><bdo id='q8PKo'><pre id='q8PKo'><center id='q8PKo'></center></pre></bdo></b><th id='q8PKo'></th></span></q></dt></tr></i><div id='q8PKo'><tfoot id='q8PKo'></tfoot><dl id='q8PKo'><fieldset id='q8PKo'></fieldset></dl></div>

        使用 SWT 显示父模式对话框

        Display parent modal dialog with SWT(使用 SWT 显示父模式对话框)
          1. <legend id='AXGyS'><style id='AXGyS'><dir id='AXGyS'><q id='AXGyS'></q></dir></style></legend>
            <i id='AXGyS'><tr id='AXGyS'><dt id='AXGyS'><q id='AXGyS'><span id='AXGyS'><b id='AXGyS'><form id='AXGyS'><ins id='AXGyS'></ins><ul id='AXGyS'></ul><sub id='AXGyS'></sub></form><legend id='AXGyS'></legend><bdo id='AXGyS'><pre id='AXGyS'><center id='AXGyS'></center></pre></bdo></b><th id='AXGyS'></th></span></q></dt></tr></i><div id='AXGyS'><tfoot id='AXGyS'></tfoot><dl id='AXGyS'><fieldset id='AXGyS'></fieldset></dl></div>

            • <bdo id='AXGyS'></bdo><ul id='AXGyS'></ul>

              <tfoot id='AXGyS'></tfoot>

              <small id='AXGyS'></small><noframes id='AXGyS'>

                <tbody id='AXGyS'></tbody>

                  本文介绍了使用 SWT 显示父模式对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  AWT/Swing 允许显示应用程序模式(阻止整个应用程序)和父模式(仅阻止父级)对话框.我怎样才能用 SWT 达到同样的效果?

                  AWT/Swing allows to show application modal (blocking the whole application) and parent modal (blocking only the parents) dialogs. How can I achieve the same with SWT?

                  推荐答案

                  为了阻塞整个应用程序,你可以创建对话框Shell,样式为SWT.APPLICATION_MODAL,打开它,然后泵送 UI 事件,直到 shell 被释放:

                  In order to block the whole application, you can create the dialog Shell with the style SWT.APPLICATION_MODAL, open it, and then pump the UI events until the shell is disposed:

                  Display display = Display.getDefault();
                  Shell dialogShell = new Shell(display, SWT.APPLICATION_MODAL);
                  // populate dialogShell
                  dialogShell.open();
                  while (!dialogShell.isDisposed()) {
                      if (!display.readAndDispatch()) {
                          display.sleep();
                      }
                  }
                  

                  如果您只想阻止对父级的输入,请尝试使用样式 SWT.PRIMARY_MODAL,尽管 Javadocs 指定(对于其他模态样式)这是一个提示;即,不同的 SWT 实现可能不会完全以相同的方式处理它.同样,我不知道有哪个实现会尊重 SWT.SYSTEM_MODAL 样式.

                  If you want to block input only to the parent, try using the style SWT.PRIMARY_MODAL, though the Javadocs specify (as for the other modal styles) that this is a hint; i.e., that different SWT implementations may not exactly handle it the same way. Likewise, I don't know of an implementation that would honor the SWT.SYSTEM_MODAL style.

                  更新:回复第一条评论

                  如果您同时打开了两个或多个主要模式,则在模式关闭之前,您不能使用这些技巧来泵送事件,因为它们可以按任何顺序关闭.代码将运行,但在当前对话框关闭以及在其之后打开的所有其他此类对话框之后,将在 while 循环后恢复执行.在这种情况下,我会在每个对话框上注册一个 DisposeListener 以在它们关闭时获得回调.像这样的:

                  If you have two or more primary modals open at the same time, you cannot use the tricks to pump the events until the modal is closed, as they could be closed in any order. The code will run, but execution will resume after the while loop after the current dialog is closed and all other such dialogs that have been opened after it. In this case, I would register a DisposeListener on each dialog to get a callback when they are closed. Something like this:

                  void run() {
                      Display display = new Display();
                      Shell shell1 = openDocumentShell(display);
                      Shell shell2 = openDocumentShell(display);
                  
                      // close both shells to exit
                      while (!shell1.isDisposed() || !shell2.isDisposed()) {
                          if (!display.readAndDispatch()) {
                              display.sleep();
                          }
                      }
                      display.dispose();
                  }
                  
                  Shell openDocumentShell(final Display display) {
                      final Shell shell = new Shell(display, SWT.SHELL_TRIM);
                      shell.setLayout(new FillLayout());
                      Button button = new Button(shell, SWT.PUSH);
                      button.setText("Open Modal Dialog");
                      button.addSelectionListener(new SelectionAdapter() {
                          @Override
                          public void widgetSelected(SelectionEvent e) {
                              System.out.println("Button pressed, about to open modal dialog");
                              final Shell dialogShell = new Shell(shell, SWT.PRIMARY_MODAL | SWT.SHEET);
                              dialogShell.setLayout(new FillLayout());
                              Button closeButton = new Button(dialogShell, SWT.PUSH);
                              closeButton.setText("Close");
                              closeButton.addSelectionListener(new SelectionAdapter() {
                                  @Override
                                  public void widgetSelected(SelectionEvent e) {
                                      dialogShell.dispose();
                                  }
                              });
                              dialogShell.setDefaultButton(closeButton);
                              dialogShell.addDisposeListener(new DisposeListener() {
                                  @Override
                                  public void widgetDisposed(DisposeEvent e) {
                                      System.out.println("Modal dialog closed");
                                  }
                              });
                              dialogShell.pack();
                              dialogShell.open();
                          }
                      });
                      shell.pack();
                      shell.open();
                      return shell;
                  }
                  

                  这篇关于使用 SWT 显示父模式对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Compiling C++ for the JVM(为 JVM 编译 C++)
                  Compile to java bytecode (without using Java)(编译成java字节码(不使用Java))
                  How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?(如何在编译时驱动 C#、C++ 或 Java 编译器计算 1+2+3+...+1000?)
                  Java ClassLoader: load same class twice(Java ClassLoader:两次加载相同的类)
                  How to debug .class files in ECLIPSE?(如何在 ECLIPSE 中调试 .class 文件?)
                  Java quot;The blank final field may not have been initializedquot; Anonymous Interface vs Lambda Expression(Java“可能尚未初始化空白的最终字段匿名接口与 Lambda 表达式)
                  <tfoot id='VUVmT'></tfoot>
                • <legend id='VUVmT'><style id='VUVmT'><dir id='VUVmT'><q id='VUVmT'></q></dir></style></legend>
                      <bdo id='VUVmT'></bdo><ul id='VUVmT'></ul>
                          <tbody id='VUVmT'></tbody>

                        <i id='VUVmT'><tr id='VUVmT'><dt id='VUVmT'><q id='VUVmT'><span id='VUVmT'><b id='VUVmT'><form id='VUVmT'><ins id='VUVmT'></ins><ul id='VUVmT'></ul><sub id='VUVmT'></sub></form><legend id='VUVmT'></legend><bdo id='VUVmT'><pre id='VUVmT'><center id='VUVmT'></center></pre></bdo></b><th id='VUVmT'></th></span></q></dt></tr></i><div id='VUVmT'><tfoot id='VUVmT'></tfoot><dl id='VUVmT'><fieldset id='VUVmT'></fieldset></dl></div>

                          1. <small id='VUVmT'></small><noframes id='VUVmT'>