• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

addActionListener in HTML

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 21863
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers for that, it gives me something to start with anyway.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a HyperlinkListener.
 
Rob Spoor
Sheriff
Posts: 21863
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But those use JEditorPane. Keith was talking about labels.
 
straws are for suckers. tiny ads are for attractive people.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!