Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6409185

Plugin/Mozilla problem - Dismissing popups leave Applet without focus

XMLWordPrintable

    • x86
    • windows_xp

      Having compiled the following code, using it with either the 1.4.2 or 5 Plug-in in Mozilla or Firefox, focus does not return to the applet when you exit a dialogue box using the keyboard. Instead it returns to the browser's URL bar. In IE, it works as expected, with focus returning to the Applet when you Alt-C the dialogue.

      package test.dialog;
      import java.awt.GridBagConstraints;
      import java.awt.GridBagLayout;
      import java.awt.Insets;
      import java.awt.event.ActionEvent;

      import javax.swing.JApplet;
      import javax.swing.JDialog;
      import javax.swing.JButton;
      import javax.swing.JOptionPane;
      import javax.swing.JTextField;


      public class MainApplet extends JApplet {

          private JTextField txtTest = null;
          private JButton btnTest = null;
          private JDialog dlgTest = null;
          
          private GridBagLayout gblTest = null;
              
          public void start() {
              this.txtTest = new JTextField();
              this.btnTest = new JButton("open dialog");
              
              this.gblTest = new GridBagLayout();
              
              this.getContentPane().setLayout(this.gblTest);

              
              
                      this.getContentPane().add(this.txtTest,
                                      this.getConstraints(0, 0, 1, 1, 100, 0,
                                                      GridBagConstraints.BOTH, GridBagConstraints.CENTER,
                                                      new Insets( 2,2,2,2),
                                                      2, 2));
                      this.getContentPane().add(this.btnTest,
                                      this.getConstraints(1, 0, 1, 1, 0, 0,
                                                      GridBagConstraints.BOTH, GridBagConstraints.CENTER,
                                                      new Insets( 2,2,2,2),
                                                      2, 2));
                      
                      this.btnTest.addActionListener(new java.awt.event.ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                                      dlgTest = new JDialog(JOptionPane.getFrameForComponent(getContentPane()), true);
                                      dlgTest.show();
                              }
                      });
          }
       
          
          private GridBagConstraints getConstraints(int aGridX, int aGridY, int aGridWidth,
                      int aGridHeight, int aWeightX, int aWeightY,
                      int aFill, int aAnchor, Insets aInsets, int aPadX,
                      int aPadY) {
              
              GridBagConstraints constraints = new GridBagConstraints();
              
              constraints.gridx = aGridX;
              constraints.gridy = aGridY;
              constraints.gridwidth = aGridWidth;
              constraints.gridheight = aGridHeight;
              constraints.weightx = aWeightX;
              constraints.weighty = aWeightY;
              constraints.fill = aFill;
              constraints.anchor = aAnchor;
              constraints.insets = aInsets;
              constraints.ipadx = aPadX;
              constraints.ipady = aPadY;
              
              return constraints;
          }
          
      }

      Switching from a JButton to a Button here (i.e. switching from Swing to AWT) fixes the problem.

            dtitov Daniil Titov (Inactive)
            mbowyer Mark Bowyer (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: