|
Buttons in JTextPane definieren
<pre>
<html>
<head>
<style>
.BTN {background-color: gray; border: 2px outset gray; cursor: pointer; }
</style>
</head>
<body>
<p style="margin-top: 0">
<a href='xxx'>call it</a><br/>
harakiri
<div class="BTN" onclick="harakiri">asdflkajsdflkj</div>
</p>
</body>
</html>
</pre>
| mousePressed-Listener der JTextPane |
int pos = jTextPane2.viewToModel(new java.awt.Point(evt.getX(), evt.getY()));
String cls = "", onclick="";
Element e = jTextPane2.getStyledDocument().getParagraphElement(pos).getParentElement();
AttributeSet as = e.getAttributes();
Enumeration<?> en = as.getAttributeNames();
while (en.hasMoreElements()){
Object it = en.nextElement();
switch(it.toString()){
case "class": cls = as.getAttribute(it).toString(); break;
case "onclick": onclick = as.getAttribute(it).toString(); break;
}
}
if (!cls.isEmpty()&&!onclick.isEmpty()){
System.out.println("BTN erwischt mit "+onclick);
}
|