3
添加的ActionListener到一个JButton在我JEditorPane
我加载具有JButton
作为HTML页面:内的JEditorPane
<object classid="javax.swing.JButton" value="Button"></object>
我如何添加一个动作监听此JButton的?
添加的ActionListener到一个JButton在我JEditorPane
我加载具有JButton
作为HTML页面:内的JEditorPane
<object classid="javax.swing.JButton" value="Button"></object>
我如何添加一个动作监听此JButton的?
试试这个。 首先创建一个自定义按钮,如图所示。
import java.awt.event.*;
import javax.swing.JButton;
public class htmlButton extends JButton
{
public htmlButton()
{
addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
System.out.println("HAI");
}
});
}
}
HTML部分:
<html>
<body>
<object classid="htmlButton" value="Button"></object> HAI
</body>
</html>
EditorPane部分
JEditorPane pan=new JEditorPane();
pan.setPage(new java.io.File("a.html").toURL());
快速谷歌搜索给出[此](https://weblogs.java.net/blog/2007/07/19/ embedding-swing-components-jeditorpane)和[this](http://java-sl.com/custom_tag_html_kit.html),两者都使用类似的策略。似乎没有简单的方法来做到这一点。 – ggovan