-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
7
-
generic
-
generic
OPERATING SYSTEM
----------------
All
FULL JDK VERSION
----------------
All (reproducible with 1.4.2, 5.0, 6 and 7)
PROBLEM DESCRIPTION
-------------------
Under certain circumstances a hyperlink in a JEditorPane can be opened by clicking in blank space near the link, rather than on the link. This even happens when the mouse pointer does not indicate that clicking will open the link, so it is counter-intuitive.
The problem occurs only when a hyperlink is the first item in a HTML paragraph. It does not occur if the link is not the first content contained within a set of <p> tags, for example:
"First link as para <p>extra text<a href='http://www.google.com/'>Para</a></p> "
or if it is not enclosed in <p> tags at all:
"First link as para <a href='http://www.google.com/'>Para</a>"
REPRODUCTION INSTRUCTIONS
-------------------------
1. Compile and run the attached testcase
2. Observe a fram containing a line of text, and a hyperlink below it.
3. Click the empty space between the text and hyperlink. Observe that
the link is opened, even though the link itself was not clicked.
TESTCASE
--------
import java.awt.BorderLayout;
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class HrefPossibleBug {
public static void main(String[] argv) {
//Editorpane
JEditorPane pane = new JEditorPane("text/html", "First link as para <p><a href='http://www.google.com/'>Para</a></p> ");
pane.setEditable(false);
pane.setOpaque(false);
pane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent event) {
if (HyperlinkEvent.EventType.ACTIVATED.equals(event.getEventType())) {
System.out.println(event.getURL());
try {
Runtime.getRuntime().exec("cmd.exe /C start http://www.google.com ");
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
}
}
}
});
//Panel
JPanel p = new JPanel();
p.add(pane);
//Frame
JFrame f = new JFrame("HyperlinkPossibleBug");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(p, BorderLayout.CENTER);
f.setSize(150, 150);
f.setVisible(true);
}
}
----------------
All
FULL JDK VERSION
----------------
All (reproducible with 1.4.2, 5.0, 6 and 7)
PROBLEM DESCRIPTION
-------------------
Under certain circumstances a hyperlink in a JEditorPane can be opened by clicking in blank space near the link, rather than on the link. This even happens when the mouse pointer does not indicate that clicking will open the link, so it is counter-intuitive.
The problem occurs only when a hyperlink is the first item in a HTML paragraph. It does not occur if the link is not the first content contained within a set of <p> tags, for example:
"First link as para <p>extra text<a href='http://www.google.com/'>Para</a></p> "
or if it is not enclosed in <p> tags at all:
"First link as para <a href='http://www.google.com/'>Para</a>"
REPRODUCTION INSTRUCTIONS
-------------------------
1. Compile and run the attached testcase
2. Observe a fram containing a line of text, and a hyperlink below it.
3. Click the empty space between the text and hyperlink. Observe that
the link is opened, even though the link itself was not clicked.
TESTCASE
--------
import java.awt.BorderLayout;
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class HrefPossibleBug {
public static void main(String[] argv) {
//Editorpane
JEditorPane pane = new JEditorPane("text/html", "First link as para <p><a href='http://www.google.com/'>Para</a></p> ");
pane.setEditable(false);
pane.setOpaque(false);
pane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent event) {
if (HyperlinkEvent.EventType.ACTIVATED.equals(event.getEventType())) {
System.out.println(event.getURL());
try {
Runtime.getRuntime().exec("cmd.exe /C start http://www.google.com ");
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
}
}
}
});
//Panel
JPanel p = new JPanel();
p.add(pane);
//Frame
JFrame f = new JFrame("HyperlinkPossibleBug");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(p, BorderLayout.CENTER);
f.setSize(150, 150);
f.setVisible(true);
}
}
- duplicates
-
JDK-6663472 clicking to the left white space of a target hyperlink activates the link
- Closed
- relates to
-
JDK-6481498 Disabled JEditorPane is firing the HyperLink Events
- Closed