Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding ActionListener to a JButton inside JEditorPane

In my JEditorPane I am loading an html page which has a JButton as:

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

How can i add an action listener to this JButton ?

like image 425
Madeyedexter Avatar asked May 25 '26 22:05

Madeyedexter


1 Answers

Try This. first create a Custom Button as shown.

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>
<body>
<object classid="htmlButton" value="Button"></object> HAI
</body>
</html>

EditorPane Part

 JEditorPane pan=new JEditorPane();
 pan.setPage(new java.io.File("a.html").toURL());
like image 145
Deepak Avatar answered May 28 '26 13:05

Deepak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!