English 中文(简体)
JAVA 烟火事件
原标题:JAVA mouseClicked event doesnt get fired on the Mac

我编制了一个方案,其中两个部分使用机动车:

  1. ResizeRectangle draws a rectangle with handles and allows moving and resizing of the rectangle. It handles MouseEvents and MouseMotionEvents (MouseMove, MousePressed, MouseDragged and MouseReleased).
  2. IconGrid draws a grid of icons within the rectangle and allows selecting (clicking) an icon. It handles the MouseClicked event for this.

It all works fine under Windows. I tried to port the program to the Mac today, but there the MouseClicked event never gets fired. I put the MouseClicked event in ResizeRectangle, but there it also wont get fired. I put the MouseReleased event in IconGrid and that does get fired. So the problem really seems to be with the mouseClicked event.

我阅读了另一篇文章,其中说,在Mac,即便是小的Pixel变化,在摩西塞克,不会发射。 但是,即使我用我对空投的点火(因此不可能在新闻和释放之间移动烟火)时,烟火事件也发火。

Anyone else had this problem? Is this a bug on the Mac?

最佳回答

该错误的来源。 我在虚拟机器中操作了SOSX,并对模拟兼容性方案进行了检查,从而造成MouseClicked事件的问题。 麻烦。

问题回答

I tried the following code on OS X with JDK1.7 and I can click on the icon and trigger the listener. Feel free to modify this code to match your situation allowing us to reproduce the issue and include this in your question.

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URL;

public class MouseClickedIcon {

  public static void showUI() throws IOException {
    JFrame testFrame = new JFrame( "TestFrame" );

    String imageSource = "http://www.mynewitguys.com/wp-content/uploads/2011/04/java1.png";

    ImageIcon icon = new ImageIcon( ImageIO.read( new URL( imageSource ) ) );
    JLabel label = new JLabel( icon );
    label.addMouseListener( new MouseAdapter() {
      @Override
      public void mouseClicked( MouseEvent e ) {
        System.out.println( "MouseClickedIcon.mouseClicked" );
      }
    } );
    testFrame.add( label, BorderLayout.CENTER );
    testFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    testFrame.pack();
    testFrame.setVisible( true );
  }

  public static void main( String[] args ) {
    EventQueue.invokeLater( new Runnable() {
      @Override
      public void run() {
        try {
          showUI();
        } catch ( IOException e ) {
        }
      }
    } );
  }
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签