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

REGRESSION: javax.swing.Popup receives a focus

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0-ea"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b42)
      Java HotSpot(TM) Client VM (build 1.6.0-ea-b42, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      javax.swing.Popup receives a focus after showing. It is regression of JDK 1.6. It works correctly in previous JDK releases 1.5 or 1.4

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a JEditorPane, register a FocusListener on it and create a Popup. You will get a focus lost event from JEditorPane, where opposite component is:
      javax.swing.Popup$DefaultFrame[frame0,0,0,123x34,invalid,hidden,layout=java.awt.BorderLayout,title=,resizable,normal],cause=ACTIVATION]
      The focus is received by popup.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Focus lost event should not occur after popup showing
      ACTUAL -
      Focus lost event occurs on JEditorPane, the popup receives a focus

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
      Just click into the JEditorPane area and watch the console output.
      Focus lost and focus gained events are printed out.
      Try to perform this on JDK 1.6 and note that the focus lost event occurs after popup displaying.
      Focus lost event is not performed on JDK 1.5 and earlier.
      */
      package javaapplication18;

      import java.awt.Color;
      import java.awt.Dimension;
      import java.awt.event.FocusListener;
      import javax.swing.JLabel;
      import javax.swing.JTextArea;
      import javax.swing.Popup;
      import javax.swing.PopupFactory;

      public class NewJFrame extends javax.swing.JFrame {
          
          public NewJFrame() {
              initComponents();
              jEditorPane1.addFocusListener(new FocusListener(){
                  public void focusLost(java.awt.event.FocusEvent e) {
                      System.out.println("");
                      System.out.println("LOST:"+e);
                  }

                  public void focusGained(java.awt.event.FocusEvent e) {
                      System.out.println("");
                      System.out.println("GAINED:"+e);
                  }
                  
              });
          }
          

          private void initComponents() {
              jScrollPane1 = new javax.swing.JScrollPane();
              jEditorPane1 = new javax.swing.JEditorPane();

              setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
              jEditorPane1.setPreferredSize(new java.awt.Dimension(300, 200));
              jEditorPane1.addMouseListener(new java.awt.event.MouseAdapter() {
                  public void mouseClicked(java.awt.event.MouseEvent evt) {
                      jEditorPane1MouseClicked(evt);
                  }
              });

              jScrollPane1.setViewportView(jEditorPane1);

              getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

              pack();
          }

          private void jEditorPane1MouseClicked(java.awt.event.MouseEvent evt) {
              PopupFactory factory = PopupFactory.getSharedInstance();
              JTextArea ta = new JTextArea("hello");
              Popup popup = factory.getPopup(null, ta,
                      100, 100);
              popup.show();
          }
          
          public static void main(String args[]) {
              java.awt.EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      new NewJFrame().setVisible(true);
                  }
              });
          }
          
          private javax.swing.JEditorPane jEditorPane1;
          private javax.swing.JScrollPane jScrollPane1;
          
      }

      ---------- END SOURCE ----------

      Release Regression From : 5.0
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.
      ###@###.### 2005-07-12 17:29:32 GMT

        Attachments

          Activity

            People

            Assignee:
            kizune Alexander Zuev
            Reporter:
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: