<bdo id='RkCgB'></bdo><ul id='RkCgB'></ul>
    1. <legend id='RkCgB'><style id='RkCgB'><dir id='RkCgB'><q id='RkCgB'></q></dir></style></legend>

      1. <tfoot id='RkCgB'></tfoot>

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

      2. <i id='RkCgB'><tr id='RkCgB'><dt id='RkCgB'><q id='RkCgB'><span id='RkCgB'><b id='RkCgB'><form id='RkCgB'><ins id='RkCgB'></ins><ul id='RkCgB'></ul><sub id='RkCgB'></sub></form><legend id='RkCgB'></legend><bdo id='RkCgB'><pre id='RkCgB'><center id='RkCgB'></center></pre></bdo></b><th id='RkCgB'></th></span></q></dt></tr></i><div id='RkCgB'><tfoot id='RkCgB'></tfoot><dl id='RkCgB'><fieldset id='RkCgB'></fieldset></dl></div>
      3. mac osx 上 java7 模式对话框的焦点问题

        Focus issues with java7 modal dialogs on mac osx(mac osx 上 java7 模式对话框的焦点问题)

          • <tfoot id='9NH1K'></tfoot>
              <bdo id='9NH1K'></bdo><ul id='9NH1K'></ul>
                <tbody id='9NH1K'></tbody>

                <small id='9NH1K'></small><noframes id='9NH1K'>

                <i id='9NH1K'><tr id='9NH1K'><dt id='9NH1K'><q id='9NH1K'><span id='9NH1K'><b id='9NH1K'><form id='9NH1K'><ins id='9NH1K'></ins><ul id='9NH1K'></ul><sub id='9NH1K'></sub></form><legend id='9NH1K'></legend><bdo id='9NH1K'><pre id='9NH1K'><center id='9NH1K'></center></pre></bdo></b><th id='9NH1K'></th></span></q></dt></tr></i><div id='9NH1K'><tfoot id='9NH1K'></tfoot><dl id='9NH1K'><fieldset id='9NH1K'></fieldset></dl></div>
                  <legend id='9NH1K'><style id='9NH1K'><dir id='9NH1K'><q id='9NH1K'></q></dir></style></legend>
                  本文介绍了mac osx 上 java7 模式对话框的焦点问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在验证一个在 mac osx 的小程序上运行的 swing 应用程序.

                  I've been validating a swing application that runs on an applet for mac osx.

                  在此验证过程中,我发现模式对话框存在以下问题:

                  During this validation I found the following issues with the modal dialogs:

                  1. 当对话框打开并且设置为 setModal(true) 时,它会阻止根窗口的内容,但是如果您单击根窗口上的某个位置,对话框会在它下方,但它应该保留在根窗口的顶部.
                  2. 如果对话框有 JTextInputField,即使单击它也不会获得焦点.

                  所以我创建了一个小程序来显示问题.你能帮我理解这里有什么问题吗?

                  So I created a small program to show the problem. Can you please help me to understand what is wrong here?

                  package com.macosx.tests;
                  
                  import java.awt.*;
                  import java.awt.event.ActionEvent;
                  import java.awt.event.ActionListener;
                  
                  import javax.swing.*;
                  
                  public class DialogExample extends JApplet{
                  
                      private static final long serialVersionUID = 1L;
                      private JPanel panel;
                      private JButton openDialogBtn;
                  
                      private void doStart() {
                          panel = new JPanel();
                          panel.setPreferredSize(new Dimension(500,500));
                  
                          openDialogBtn = new JButton("open dialog");
                          openDialogBtn.addActionListener(new ActionListener(){
                  
                              @Override
                              public void actionPerformed(ActionEvent arg0) {
                                  ModalDialog dialog = new ModalDialog(panel, true);
                                  dialog.setVisible(true);
                              }
                  
                          });
                          panel.add(openDialogBtn);
                          setContentPane(panel);
                      }
                  
                  
                      class ModalDialog extends JDialog {
                          private static final long serialVersionUID = 1L;
                  
                          public ModalDialog(Component parent, boolean modal) {
                              Dimension dimensionParentFrame = parent.getSize();
                              setSize(new Dimension((parent == null) ? 300 : dimensionParentFrame.width / 2, 75));
                  
                              setModal(modal);
                              setModalityType(ModalityType.APPLICATION_MODAL);
                  
                              JTextField txtField = new JTextField();
                              add(txtField, BorderLayout.CENTER);
                          }
                      }
                  
                  
                      @Override
                      public void start() {
                          try {
                              SwingUtilities.invokeAndWait(new Runnable() {
                                  public void run() {
                                      doStart();
                                  }
                              });
                          } catch (Exception e) {
                              throw new RuntimeException(e);
                          }
                      }
                  
                  }
                  

                  使用上述创建一个 .jar 文件(test.jar).完成后,创建一个包含以下内容的 html 文件:

                  Use the above to create a .jar file (test.jar). Once that is done, create a html file with the following content:

                  <html>
                  <head>
                  <title>Dialog test Applet</title>
                  </head>
                  <body>
                  <applet id="DialogTestApplet" height="800" width="600"
                    code="com.macosx.tests.DialogExample"
                    archive="test.jar">
                  </applet>
                  </div>
                  </body>
                  </html>
                  

                  完成后,运行 html 文件.您将看到一个带有灰色背景和一个按钮的小程序.然后尝试:

                  When this is done, run the html file. You'll see an applet with a gray background and with a button. Then try to:

                  1. 点击按钮打开对话框.之后,单击灰色区域的某处:对话框位于浏览器窗口下方,但它应该保留在顶部,对吧?
                  2. 点击按钮打开对话框.之后单击对话框的文本字段并尝试编写一些内容:文本对话框没有获得焦点.

                  那么,我在这里做错了什么?请问有mac电脑的人可以测试一下吗?

                  So, what am I doing wrong here? Can someone with a mac computer test this please?

                  谢谢

                  规格:

                  java.vendor    Oracle Corporation
                  java.version   1.7.0_07
                  os.name        Mac OS X
                  os.version     10.7.4
                  
                  browser        firefox 15
                  

                  注意:请注意,这仅在小程序在浏览器上运行且仅在 mac osx 上运行时才会发生.

                  推荐答案

                  我找到了另一种解决方法.当窗口打开时,显示一个选项窗格几毫秒然后关闭它.它将焦点放在选项窗格上,然后返回对话框,允许忽略该错误.

                  I found another workaround. When the window is opened, show an optionpane for a few milliseconds and close it. It give the focus to the optionpane and then back to the dialog, allowing to ignore the bug.

                  将这段代码添加到您的对话框构造函数中,它应该可以工作:

                  Add this snipet of code to your dialog constructor and it should work:

                  addWindowListener(new WindowAdapter(){
                  public void windowOpened(WindowEvent e){
                      JOptionPane pane = new JOptionPane();
                      final JDialog dialog = pane.createDialog("Please Wait");
                      Timer timer = new Timer(50, new ActionListener() {
                          public void actionPerformed(ActionEvent e) {
                              dialog.dispose();
                          }
                      });
                  timer.setRepeats(false);
                  timer.start();
                  dialog.setVisible(true);
                  }
                  

                  这篇关于mac osx 上 java7 模式对话框的焦点问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 表达式)
                  <legend id='WFzcl'><style id='WFzcl'><dir id='WFzcl'><q id='WFzcl'></q></dir></style></legend>

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

                    <tbody id='WFzcl'></tbody>
                    <bdo id='WFzcl'></bdo><ul id='WFzcl'></ul>

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

                          <tfoot id='WFzcl'></tfoot>