to 楼上: 不是不想执行mouseClicked()中的动作,而是当鼠标点击的是JEditorPane中的超链接时不执行mouseClicked()中的动作,当在JEditorPane的其它地方点击时是要执行mouseClicked()中的动作的.
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.
sorry, cannot type chinese on my computer
to up: In my test,HyperlinkEvent was generated 10~30 milliseconds earlier before MouseEvent.
我不太清楚有没有现成的函数可以用,如果担心不太安全的话。楼主看看下面这种处理是否可行?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; } });
不是不想执行mouseClicked()中的动作,而是当鼠标点击的是JEditorPane中的超链接时不执行mouseClicked()中的动作,当在JEditorPane的其它地方点击时是要执行mouseClicked()中的动作的.
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.
In my test,HyperlinkEvent was generated 10~30 milliseconds earlier before MouseEvent.
public void mouseClicked(MouseEvent e) {
sleep(50);
if(flag){
....
}
}
});
jp.addHyperlinkListener(new HyperlinkListener(){
public void hyperlinkUpdate(HyperlinkEvent e) {
flag = false;
....
sleep(100);
flag = true;
}
});
mouseClicked()并没有区分左右键;这是一个产品信息的about窗口,单击鼠标则关闭窗口。
if(e.getButton()==e.BUTTON2){
右键
}