Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes addActionListener in HTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "addActionListener in HTML" Watch "addActionListener in HTML" New topic
Author

addActionListener in HTML

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
This is a long shot, but is it possible to call a Swing actionPerformed/actionListner from a HREF within a Swing app in the same way as say from a JButton?

I am using a StringBuffer to create a HTML label to display some text to my Swing app page, but I need links to another panel within this page.
So I was thinking (hoping) there might be some way to create a type funtion within the page.

Anyone have any ideas (presuming my explanation actually makes sense)

KS
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

You can't, no. But you can add a MouseListener to the label, and respond to its mouseClicked event. That leaves you the problem of finding out where in the string you clicked, but maybe you can figure that out yourself.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Cheers for that, it gives me something to start with anyway.
Stanislav Lapitsky
Ranch Hand

Joined: Dec 01, 2009
Posts: 53
Actually you can. Just add a muse listener to the JEditorPane/JTextPane. When it's clicked you can get position in the document using viewToModel() method passing the click point. Then get the HTMLDocument and call getCharacterElement() to get leaf Element. Then check the Element's attributes. If the attributes contain link attrs get do a desired action for the specific attrs.
That's source code snippet from HTMLEditorKit.


Hope this helps.

Regards,
Stas
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Use a HyperlinkListener.


luck, db
There are no new questions, but there may be new answers.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

But those use JEditorPane. Keith was talking about labels.
 
Don't get me started about those stupid light bulbs.
 
subject: addActionListener in HTML
 
Similar Threads
Passing values to and from HTML
MathML support in Java Swing application.
Any solutions to support MathML within JEditorPane
Getting Page Source In The Servlet
Using swing in Java