这里所谓的同时应该还是有先后的吧,就好像鼠标拖曳之前肯定会发生鼠标点击事件。如果HyperlinkEvent先于MouseEvent发生,那么简单设定一个flag  HY事件里面改变flag的值,在mouse里面加个对flag的判断应该就可以。如果猜测错误,那再说吧,会比较麻烦

解决方案 »

  1.   

    如果不想执行mouseClicked()中的动作,那为什么要注册它呢。
      

  2.   

    to 楼上:
        不是不想执行mouseClicked()中的动作,而是当鼠标点击的是JEditorPane中的超链接时不执行mouseClicked()中的动作,当在JEditorPane的其它地方点击时是要执行mouseClicked()中的动作的.
      

  3.   


    I read the source, HyperlinkEvent is generated by mouseClick(). That means your mouseClick() will happen before hyperlinkUpdate(). Because a Mouse Click event will be generated first, then JEditorPane try to check if a link is clicked. If a link is clicked, a HyperlinkEvent will be dispatched and hyperlinkUpdate() is called. Two suggestion:
    1. try to use another framework, avoid processing mouseClick and hyperlinkUpdate at the same time
    2. If have to, under mouseClick() you must check the mouse position is within a link before doing other things. 
       There are two types of link, <a href> and <map>. Copy the source code from 
    HTMLEditoreKit.LinkController can solve <a href>. But you cannot solve <map>, unless you write your own codes. Because to determine if it's a <map> link, HTMLDocument and java.swing.text.html.Map class are used. You're unlucky, Map is package-access class. So methods of Map, such as Map.getArea(), cannot be accessed in your codes because I don't think you'll put your code under java.swing.text.html package.
       
    If no <map>, I can give you a solution. If you want to handle <map>, try to write your own code.
      

  4.   

    sorry, cannot type chinese on my computer
      

  5.   

    to up:
        In my test,HyperlinkEvent was generated 10~30 milliseconds earlier before MouseEvent.
      

  6.   

    我不太清楚有没有现成的函数可以用,如果担心不太安全的话。楼主看看下面这种处理是否可行?100毫秒左右的损失应该是可以被忽略的,这样可以保证你的HyperlinkEvent肯定会先上来。jp.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    sleep(50);
                    if(flag){
                    ....
                    }
                }
            });
            jp.addHyperlinkListener(new HyperlinkListener(){
                public void hyperlinkUpdate(HyperlinkEvent e) {
                    flag = false;
                    ....
                    sleep(100);
                    flag = true;
                }
            });
      

  7.   

    比如在机器非常繁忙的时候。
    mouseClicked()并没有区分左右键;这是一个产品信息的about窗口,单击鼠标则关闭窗口。
      

  8.   

    如果只是为了关闭窗口,添加个button或者一个处理关闭的链接不可以么?可以区分左右键的
    if(e.getButton()==e.BUTTON2){
    右键
    }
      

  9.   

    原来的方案是用button的,不过觉得button破坏了界面的和协性。用右键与用户习惯不符。其实我只是想知道有没有直接的解决方案,看来是没有结果了,先结帐吧。