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

merlin components receive focus AFTER mousePressed event

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.4.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: bsC130419 Date: 07/10/2001


      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)


      - start application (window appears)
      - click on button (just to make sure the list doesn't have the focus)
      - click on "apples"

      My output (Windows 98):

      1. JDK 1.4 beta
      list pressed - no focus
      list released - has focus

      2. JDK 1.3.1
      list pressed - has focus
      list released - has focus

      So 1.4 reports NO focus, whereas 1.3.1 reports focus on the mousePressed
      event.

      The component receivedthe focus BEFORE the mousePressed event in 1.3.1, whereas with 1.4 beta it receives it AFTER the mousePressed event.

      While this is not a major bug, it certainly will be a backward compatibility
      issue.


      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class EventDemo extends JFrame {
        JList jList = new JList();
        JButton jButton = new JButton();


        public EventDemo() {
          this.getContentPane().setLayout(new BorderLayout());
          jList.addMouseListener(new EventDemo_jList_mouseAdapter(this));
          DefaultListModel listModel = new DefaultListModel();
          listModel.addElement("apples");
          listModel.addElement("pears");
          jList.setModel(listModel);
          jList.setPreferredSize(new Dimension(100, 70));
          this.getContentPane().add(jList, BorderLayout.CENTER);
          // the button is only added to have a place to click on in order to get
          // the focus away from the jList
          jButton.setText("Relax");
          this.getContentPane().add(jButton, BorderLayout.NORTH);
        }

        // method to exit properly; not relevant for demonstration of bug
        protected void processWindowEvent(WindowEvent e) {
          super.processWindowEvent(e);
          if(e.getID() == WindowEvent.WINDOW_CLOSING) {
            System.exit(0);
          }
        }

        public static void main(String[] args) {
          EventDemo demo = new EventDemo();
          // pack and center on screen
          demo.pack();
          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          demo.setLocation((screenSize.width - demo.getWidth()) / 2,
      (screenSize.height - demo.getHeight()) / 2);
          demo.setVisible(true);
        }

        void jList_mousePressed(MouseEvent e) {
          if (jList.hasFocus()) {
            System.out.println("list pressed - has focus");
          } else {
            System.out.println("list pressed - no focus");
          }
        }

        void jList_mouseReleased(MouseEvent e) {
          if (jList.hasFocus()) {
            System.out.println("list released - has focus");
          } else {
            System.out.println("list released - no focus");
          }
        }



      }

      class EventDemo_jList_mouseAdapter extends java.awt.event.MouseAdapter {
        EventDemo adaptee;

        EventDemo_jList_mouseAdapter(EventDemo adaptee) {
          this.adaptee = adaptee;
        }

        public void mousePressed(MouseEvent e) {
          adaptee.jList_mousePressed(e);
        }

        public void mouseReleased(MouseEvent e) {
          adaptee.jList_mouseReleased(e);
        }
      }
      (Review ID: 127744)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              dmendenhsunw David Mendenhall (Inactive)
              Reporter:
              bstrathesunw Bill Strathearn (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: