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

Inconsistent mouse enter/exit notification based on LayoutManager

XMLWordPrintable

    • sparc
    • solaris_2.5.1


      To avoid breaking the 1.0.2 event behavior on a Component, I wrap that
      component in a 1.1 Panel and add a listener to the Panel. I get inconsistent
      results based on the layout manager that is used. I am most interested in
      getting valid enter/exit notification on null layout.

      I have created a test application to show the problem. To use:
      - save program as main.java
      % javac main.java
      % java main <layout manager>
        - <layout manager> is border, grid, flow, or null
      Move the mouse into and out of the "Enter/Exit" button, notice the correct
      behavior for border and grid layouts and the inconsistent behavior for
      flow and null layout.

      I am unable to obtain enter/exit notification on components using the 1.0.2
      Event model in my 1.1 tool without a fix to this bug. I believe that I can
      add a mouse listener directly to the 1.0.2 Component and get proper enter/exit
      notification, but this breaks the 1.0.2 event behavior permanently. I have
      filed a bug report on this problem as well (4025729).

      import java.applet.*;
      import java.awt.*;
      import java.awt.event.*;

      public class main extends Applet {

      static String Args[];

      public static void main(String args[]) {
          Applet ctk = new main();
          Args = args;
          ctk.init();
      }

      public void init() {
          Frame f = new Frame();
          Panel bp = new Panel(new BorderLayout());
          Button button = new Button("Enter/Exit");
          bp.add("Center", button);
          bp.addMouseListener(new EnterExitListener());
          Panel topPanel = new Panel();
          f.add("Center", topPanel);
          if (Args.length == 0)
      System.out.println("usage: java main <layout>, where layout is border, grid, or null");
          else if (Args[0].equals("border")) {
      topPanel.setLayout(new BorderLayout());
      f.add("Center", topPanel);
      topPanel.add("West", new Button("WestDummy"));
      topPanel.add("Center", bp);
      topPanel.add("East", new Button("EastDummy"));
          } else if (Args[0].equals("grid")) {
      topPanel.setLayout(new GridLayout(1, 3));
      topPanel.add(new Button("WestDummy"));
      topPanel.add(bp);
      topPanel.add(new Button("EastDummy"));
          } else if (Args[0].equals("flow")) {
      topPanel.setLayout(new FlowLayout());
      topPanel.add(new Button("WestDummy"));
      topPanel.add(bp);
      topPanel.add(new Button("EastDummy"));
          } else if (Args[0].equals("null")) {
      topPanel.setLayout(null);
      Button wButton = new Button("WestDummy");
      topPanel.add(wButton);
      wButton.setLocation(0,10);
      wButton.setSize(90,100);
      topPanel.add(bp);
      bp.setLocation(100,10);
      bp.setSize(90,100);
      Button eButton = new Button("EastDummy");
      topPanel.add(eButton);
      eButton.setLocation(200,10);
      eButton.setSize(90,100);
          }
          f.setSize(new Dimension(300, 300));
          f.show();
      }

      public void start() {
      }

      public void stop() {
      }

      public void destroy(){
      }

      public void paint(Graphics g) {
      }

      }

      class EnterExitListener implements MouseListener {

      public void mouseEntered(MouseEvent e) {
          System.out.println("Mouse entered");
      }

      public void mouseExited(MouseEvent e) {
          System.out.println("Mouse exited");
      };

      public void mouseClicked(MouseEvent e) {};
      public void mousePressed(MouseEvent e) {};
      public void mouseReleased(MouseEvent e) {};

      }

            duke J. Duke
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: