简体   繁体   English

将ActionListener添加到JEditorPane中的JButton

[英]Adding ActionListener to a JButton inside JEditorPane

In my JEditorPane I am loading an html page which has a JButton as: 在我的JEditorPane我正在加载一个具有JButton的html页面:

<object classid="javax.swing.JButton" value="Button"></object>

How can i add an action listener to this JButton ? 如何为此JButton添加动作侦听器?

Try This. 尝试这个。 first create a Custom Button as shown. 首先创建一个Custom Button,如图所示。

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 part: HTML部分:

<html>
<body>
<object classid="htmlButton" value="Button"></object> HAI
</body>
</html>

EditorPane Part EditorPane Part

 JEditorPane pan=new JEditorPane();
 pan.setPage(new java.io.File("a.html").toURL());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM