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

False JWindow windowLostFocus

    Details

    • Subcomponent:
    • OS:
      linux_ubuntu

      Description

      FULL PRODUCT VERSION :
      java version "1.7.0_40"
      Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
      Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux senleft-ThinkStation-S20 3.2.0-54-generic #82-Ubuntu SMP Tue Sep 10 20:08:42 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      False JWindow windowLostFocus event generated while all operations made within the same JWindow

      REGRESSION. Last worked in version 6u43

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create JWindow and place any component to it. Source code for an executable test case contains JWindow and JList. Selected some list items consequently.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      windowLostFocus event don't expected for all operations within JWindow.
      Below is a output for jdk1.6.31 version
      listSelectionListener:valueChanged
      mousePressed
      windowGainedFocus
      listSelectionListener:valueChanged
      Selected: 3
      ***************
      listSelectionListener:valueChanged
      mousePressed
      listSelectionListener:valueChanged
      Selected: 7
      ***************
      ACTUAL -
      windowLostFocus generated between two consequently list selection operation within the same JWindow.
      Below is a output for jdk1.6.40 version
      jdk1.7.40
      listSelectionListener:valueChanged
      mousePressed
      windowGainedFocus
      listSelectionListener:valueChanged
      Selected: 3
      ***************
      windowLostFocus
      listSelectionListener:valueChanged
      mousePressed
      windowGainedFocus
      listSelectionListener:valueChanged
      Selected: 7
      ***************

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class MouseAdapterDemo extends JFrame{

          private final DefaultListModel dataModel = new DefaultListModel();
          private JList jList = new JList(dataModel);

          private ListSelectionListener listSelectionListener = new ListSelectionListener() {

              public void valueChanged(ListSelectionEvent e) {
                  System.out.println("listSelectionListener:valueChanged");
                  if (e.getValueIsAdjusting()) {
                      return;
                  }
                  System.out.println("Selected: " + jList.getSelectedValue());
                  System.out.println("***************");

              }
          };

          public MouseAdapterDemo() {
              super("MouseAdapterDemo");
              setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              setSize(400, 300);
              setVisible(true);
              CustomJWindow window = new CustomJWindow(this);
              window.setAlwaysOnTop(true);
              window.setSize(100, 300);
              window.setVisible(true);
              initList();
              window.add(jList);
          }

          private void initList() {
              DefaultListModel model = (DefaultListModel) jList.getModel();
              for (int i = 0; i < 10; i++) {
                  model.addElement(i);
              }
              jList.addMouseListener(new MouseL());
              jList.addListSelectionListener(listSelectionListener);
          }

          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      new MouseAdapterDemo();
                  }
              });
          }

          class MouseL extends MouseAdapter {
              @Override
              public void mousePressed(MouseEvent e) {
                  System.out.println("mousePressed");
              }
          }

          class CustomJWindow extends JWindow {

              public CustomJWindow(Frame owner) {
                  super(owner);
                  addWindowFocusListener(focusListener);
              }

              private WindowFocusListener focusListener = new WindowFocusListener() {

                  public void windowGainedFocus(WindowEvent e) {
                      System.out.println("windowGainedFocus");
                  }

                  public void windowLostFocus(WindowEvent e) {
                      System.out.println("windowLostFocus");
                  }
              };
          }


      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              dmarkov Dmitry Markov
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: