Questionable Legality: HyperlinkListener without URLs

Hey guys,
My goal is to have website-style links in a JEditorPane that cause certain behaviors in my GUI when the user clicks them.
The SSCCE below works exactly how I'd want it to. The only problem is, I feel a bit dirty using a HyperlinkListener in such a seemingly non-standard way. Is there a better/standard way to accomplish my goal? I thought of using a JTextPane with clickable JLabels inserted where my hyperlinks now go, but using the HyperlinkListener seems simpler.
Here is the potentially shameful SSCCE I came up with:
import java.awt.Color;
import javax.swing.*;
import javax.swing.event.*;
public class EditorLinkTest {
   public EditorLinkTest() {
      JFrame frame = new JFrame("EditorPane Link Test");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      final JEditorPane textComponent = new JEditorPane();
      textComponent.setEditable(false);
      textComponent.setContentType("text/html");
      String text = "Background color:<br/>" +
         "<a href='red'>Click here</a> for red.<br/>"+
         "<a href='white'>Click here</a> for white.<br/>";
      textComponent.setText(text);
      textComponent.addHyperlinkListener(new HyperlinkListener() {
         public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
               try {
                   //e.getURL() would cause a NPE, for obvious reasons
                  String link = e.getDescription();
                  System.out.println("Link: " + link);
                  if(link.contains("red")){
                     textComponent.setBackground(Color.RED);
                  else if(link.contains("white")){
                     textComponent.setBackground(Color.WHITE);
               catch (Exception ex) {
                  System.err.println("Error: " + ex);
      JScrollPane scrollPane = new JScrollPane(textComponent, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      frame.add(scrollPane);
      frame.setSize(200, 200);
      frame.setVisible(true);
   public static void main(String[] args) {
      new EditorLinkTest();
}So, what say you? Am I just being paranoid about what is a "valid" use of a HyperlinkListener? Or should I man up and change my GUI so that it uses a JTextPane with clickable components that cause the desired behavior? Do I not fix what ain't broke, or do I delete this dirty code before anybody else sees it?
I'm on the fence myself, so any input would be appreciated.

I see nothing on my stdout (I'm using JDK1.6.0_11, WinXP) when I click the links... And I'm not able to debug why (never used HyperlinkEvents before).That's really weird. I'm using JDK1.6.0_17, WinXP. I'll have to investigate whether it works other platforms, I suppose :(Works home (JDK 1.6.0_11, WInXP too). Beats me...
Anyway at least I could investigate forward...
Instead of "parsing" the event's description, couldn't you get its Element property, and look at the Element's attributes?I've been playing with this for a while now, but I can't seem to find anything useful from HyperlinkEvent.getSourceElement().anything. Am I missing something?I tried this. Seems to work:
         public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
               try {
                   //e.getURL() would cause a NPE, for obvious reasons
                  // String link = e.getDescription();
                  AttributeSet attrs = e.getSourceElement().getAttributes();
                  AttributeSet aTagAttrs = (AttributeSet)attrs.getAttribute(HTML.Tag.A);
                  String link = (String)aTagAttrs.getAttribute(HTML.Attribute.HREF);
                  System.out.println("href VALUE: " + link);
                  if(link.equals("red")){
                     textComponent.setBackground(Color.RED);
                  else if(link.equals("white")){
                     textComponent.setBackground(Color.WHITE);
               catch (Exception ex) {
                  System.err.println("Error: " + ex);
         }I don't know what worse... Parsing the undocumented description string, vs relying on the poorly-documented types and hierarchy of AttributeSets... Assuming this latter is reliable, I much prefer it: after all once digged through it, makes sense that there is an <A> tag, whose HREF attribute contains the link string. What makes less sense is that I had to inspect the private attributes of JDK classes in a debugger to discover the types and values of those! >o(

Similar Messages

  • How do I change my security questions and answers without setting up a new account. I can't remember the answers to the questions that they ask.

    How do I change my security questions and answers without setting up a new account. I can't remember the answers to the questions that they ask.

    1. See my User Tip for some help: Some Solutions for Resetting Forgotten Security Questions: Apple Support Communities.
    2. Here are two different but direct methods:
        a. Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
        b. Call Apple Support in your country: Customer Service: Contacting Apple for support
            and service.
    3. For other queries about Apple ID see Frequently asked questions about Apple ID.
    4. Rescue email address and how to reset Apple ID security questions
    5. For online assistance use Apple - Support - Express Lane

  • I have installed Adobe Reader 11.0.07 for Mac OS 10.9.3. Have asked this question numerous time without results. The problems I am having are: I cannot scroll using the side slider on downloaded PDF files, nor can I fill in fillable files. Also, and this

    I have installed Adobe Reader 11.0.07 for Mac OS 10.9.3. Have asked this question numerous time without results. The problems I am having are: I cannot scroll using the side slider on downloaded PDF files, nor can I fill in fillable files. Also, and this is extremely irritating, I cannot re-initialize the same file or initialize and another PDF file after I have initialized the first file. If you cannot help please let me know if should use an earlier  version of Reader or find anther company that has the appropriate software.

    Perhaps you missed that you started a discussion at I have OS 10.9.2 and have downloaded latest version of Reader 11. I can no longer fill in form or scroll using the side bar. and you did not respond to the last post there.

  • HT201240 How can I change my Apple ID password security questions and answers without providing a rescue email address?

    How can I change my Apple ID password security questions and answers without providing a rescue email address?

    Click here for information. If you can't reset them through the method described in that article, contact the iTunes Store staff via the link in the 'Additional Information' section.
    (105909)

  • First question didn't post: URL SUFFIX not working....

    I have been using the add-on URL SUFFIX for years.
    I haven't changed any settings. I used to be able to type into the URL bar, AOL and it would add the necessary www. and .com at the end.
    Any site that I enter, be it Sears or Bravotv or what have you, I automatically get a search page, with what I'm looking for as the first answer, but in the Url bar, something with Google and a few + signs and greyed out areas now show.
    I have the latest version of Firefox for Mac, and all of my plugins and add ons are up to date. Also, my Firefox updates are current.
    Thanks.

    SOLVED..
    add - on called BROWSE BY NAME 1.1 for Firefox, allows you to type into the url bar, without taking you to a google search page.
    I just added it and tried it and it works great. Solved my problem on my own . WOuld have deleted the question but I can't figure out how. :)

  • Group and legal costs without Material Ledger

    I was wondering is there a way we could have both the group cost and the legal cost in the system without having to configure material ledger. Currently we have Group cost in the system and no legal cost.
    Any help would be greatly appreciated.

    Hi NIK83,
    There is no other way to have multiple valuations w/o having ML in SAP
    ML is the only solution... If you want to upload the legal values, you can use the tax price or commercial price fields and take out a report comparing the 2 values using T code MRN9
    but, you will have to uplaod these values.. these cant be calculated w/o ML
    Regards
    Ajay M

  • Update on question for parameters in URL opening a BSP iview

    Hi again gurus.
    I wanted to do an update on this thread: How do you create a URL with parameters for a BSP iview? but choose to do the update as this new question instead.
    Well, in order to open a BSP iview from an external page shown in an Application Integrator iview in our portal AND FILL IN A FIELD, a link of this type is used on the external page:
    http://<server:port>/sap/bc/bsp/sap/z_purchase_req/process.htm?System=ABG_R3_ARD&mnr%3D9780198603641
    If you read the other thread you will see that I couldn't use a link of the following type since it opened up something like the stuff found under "System Administration > Support > SAP Application" and there asked for BSP application and start page!
    http://<server:port>/irj/servlet/prt/portal/prtroot/com.sap.portal.appintegrator.sap.bwc.BSP?System=ABG_R3_ARD&SAP_TCode=Z_PURCHASE_REQ&STARTPAGE=process.htm
    But the first link works so far as it opens up the correct transaction BUT the parameter won't get into the field. Does anyone know how to "format" the parameter correctly? When you open an iview of Transactional type you can use a URL like this (and it works also with writing parameter into a field):
    http://<server:port>/irj/servlet/prt/portal/prtroot/com.sap.portal.appintegrator.sap.bwc.Transaction?System=ABG_R3_ARD&SAP_TCode=ZARTS2&SAP_Dynp_Params=S_MATNR-LOW%3D9789146212720
    It's the part ...&SAP_Dynp_Params=... that is of interest here. Should it also be used when working with URLs opening BSP iviews or not? Or should something similar be used instead? The name of the field "mnr" is correct in the BSP URL, at least I think so, I found it in the Web Application Builder under tab "Page Attributes". I have tried both "=" and "%3D" in the URL but neither works.
    Any suggestions about the parameter format for this link or another completely different but working URL format would be extremely appreciated!
    Best regards
    Benny Lange

    the Appintegrator Documentation says you can use something like <User.[AttributeName]>, so <User.email> and <User.company> (not sure about capital letters) should work.
    Hope that helps.
    PD

  • Question about carDemo - wrong URL shown

    Made carDemo running on my machine successfully. Kool stuff!
    Found something wrong, the question may seem silly.
    The URL shown on my brower is always the previous page:
    e.g. http://localhost:8080/jsf-cardemo/chooseLocale.jsf -- for the store front page
    http://localhost:8080/jsf-cardemo/storeFront.jsf -- for the carDetails page
    It can be quite dangeous if I do a page refresh. Is there anything wrong?

    Thanks!
    Such a trivial problem. Why the example is released with this problem? It really confuses the user, not mention it will cause problem with refesh.
    Will try the prefix mapping (/faces/), hopefully, it will solve the problem.

  • [SOLVED] Package without URL

    Hello everyone!
    I've made a very small package. It's made up of only two files (two small shell scripts), so I added them along with the PKGBUILD in the source tarball. I don't have a server to host the files, nor would I like to set up one (or register somewhere) to just store three kilobytes. So, my PKGBUILD has no url variable.
    I've looked in the official guidelines, at the wiki, and it just says you have to put an URL. What should I do, then?
    Thanks in advance. Best regards,
    Kalrish
    Last edited by Kalrish (2013-06-23 18:00:19)

    I'm with Scimmia, but have additional reasons: size isn't the only relevant factor.  When packages do contain some form of code in the aur tarball (patches, install scripts, etc) it is (or should be!) only because the upstream source of the original source code (and/or installation procedure) is incompatible with arch linux.  So this might include a patch to put things in the right directory, or a script to go in /usr/bin/ to launch a binary put in an odd location.
    But in this case you are the upstream source.  They're small ... so?  They're yours.  You don't need to fix someone else's work and include the fix in the tarball ... it's your work.
    Also, github is handy for many other purposes.  And I can assure you they do not 'spam' you with any sort of adds, or any nonsense.  They also have *phenomenal* service reps.  I emailed a question one day and within hours I had a very courteous, clear, and complete answer ... and I'm not subscribing, just using their free service.  I avoid signing up for things as much as possible, but github is really just a great company/organization/site/whatever.
    Last edited by Trilby (2013-06-23 18:04:00)

  • Any solution for swf file without url link embedded?

    As a long shot just thought I would ask.
    Received a swf file which needs to be linked to a url address BUT the company that produced it has not embedded the link in the .fla file!!!!!
    In the past I seem to remember there is not a way to link the swf via html or maybe so but only via javascript or some complex solution. Is this still the case or has someone found an elegant solution to the issue in recent times?
    Thanks
    Os

    Ken Binney wrote:
    Hi Os -
    Can you get the fla file?
    Hi Ken,
    Unfortunately not. If I could I don't think it would be much help as I'm out of touch with Flash. I used to dabble around in Flash a bit years ago but didn't persist as I thought it required a bit more time to really get to know than I could give it.
    I know it's a relatively simple procedure to add a getURL frame to the .fla file as I done it myself in the past. Not sure why whoever did it hasn't included the link as it's an advert to attract people to a certain url.
    I guess they will just have to sort it themsleves.
    Thanks for replying. Just though things move quickly and some genius might have discovered a way to add a link without having to resort to the .fla file.

  • Destype=Printer; without url being redirected or popup window

    In our old client/server enviroment, our users printed some reports directly to the printer. In the Oracle 9I web server, we user web.show_document to run a report with '_blank' so that the form is not changed to the report URL. Destype=Printer is in the URL and printers are setup on our AIX Unix server. It works but our users do not want to see any popup window and want to stay in a form. A message comes up saying "Report ran successfully". The users don't want this message or the window that it is in caused by web.show_document. They just want to print without seeing anything on the screen. Is this possible?

    Hi,
    Please try with following options
    1. Enter DESNAME with in quotes as '\\rgasion\F5-copyroom east -1' and print the Report
    (or)
    2. Go To Windows Printer Setup, Change printer name to F5-copyroom_east_-1(Remove space with underscore), then try to print
    or
    3. If you printer is Shared Network printer, Open Printer Property dialog and go to Sharing page, there set share name as F5-copyroom_east_-1, then try to print
    Thanks
    Oracle Reports Team

  • How can we open a new instance of Firefox without URL bar and any other control (except PREV, NEXT and RELOAD)?

    Dear Volunteers,
    I am looking for a solution for Firefox Win App and Mobile Apps where on click of a button from the website page, we should be able to launch a new instance of firefox instance (like a popup box) with following features:
    a. It SHOULD NOT have any URL bar to display.
    b. It SHOULD NOT show any plug-ins or any other functionality except Previous, Next and Reload.
    c. This instance of firefox should always be on-top of all other application.
    Please advise, how firefox can be customized to offer in all platforms by default.
    With lot of hope from this volunteer community,
    Rajiv

    You would need your visitors to install some kind of add-on, since web pages do not have permission to block the display of the page address and users do not need to allow a new window to be modal and block other Firefox windows, much less other OS windows.
    Over the years, people have developed extensions for kiosk-style displays. You could investigate those for ideas.

  • Japanese Characters working as URL parameters, turning to question marks when in URL string itself

    I'm having some trouble getting coldfusion to see japanese
    characters in the URL string.
    To clarify, if I have something like this:
    http://my.domain.com/index.cfm?categorylevel0=Search&categorylevel1=%E3%82%A2%E3%82%B8%E3% 82%A2%E3%83%BB%E3%83%93%E3%82%B8%E3%83%8D%E3%82%B9%E9%96%8B%E7%99%BA
    All of my code works correctly and the server is able to pass
    the japanese characters to the database and retrieve the correct
    data.
    If I have this instead:
    http://my.domain.com/index.cfm/Search/%E3%82%A2%E3%82%B8%E3%82%A2%E3%83%BB%E3%83%93%E3%82% B8%E3%83%8D%E3%82%B9%E9%96%8B%E7%99%BA
    My script (which works fine with English characters) parses
    CGI variables and converts these to the same URL parameters that I
    had in the first URL using a loop and a CFSET url.etc..
    In the first example, looking at the CF debug info shows me
    what I expect to see:
    URL Parameters:
    CATEGORYLEVEL0=Search
    CATEGORYLEVEL1=アジア・ビジネス開発
    In the second example it shows me this:
    URL Parameters:
    CATEGORYLEVEL0=Search
    CATEGORYLEVEL1=???·??????
    Can anyone suggest means for debugging this? I'm not sure if
    this is a CF problem, an IIS problem, a JRUN problem or something
    else altogether that causes it to lose the characters if they are
    in the URL string but NOT as a parameter.

    My suggestion was that you test with the
    first url, not the second. However, I can see a source of
    confusion. I overlooked your delimiter, "/". It should be "?" and
    "=" in this case. With these modifications, we get
    <cfif Len(cgi.query_string) neq 0>
    <cfset i = 1>
    <cfloop list="#cgi.query_string#" delimiters="&"
    index="currentcatname">
    <cfoutput>categorylevel#i# =
    #ListGetAt(currentcatname,2,"=")#</cfoutput><br>
    <cfset i = i + 1>
    </cfloop>
    If it is a failing of Coldfusion, the above test should fail,
    too.
    Now, an adaptation of the same test to your second url.
    <cfset url2 = "
    http://my.domain.com/index.cfm/Search/%E3%82%A2%E3%82%B8%E3%82%A2%E3%83%BB%E3%83%93%E3%82% B8%E3%83%8D%E3%82%B9%E9%96%8B%E7%99%BA">
    <cfset query_str =
    ListGetAt(replacenocase(url2,".cfm/","?"),2,"?")>
    <cfif Len(query_str) neq 0>
    <cfset i = 1>
    <cfloop list="#query_str#" delimiters="/"
    index="currentcatname">
    <cfoutput>categorylevel#i# =
    #currentcatname#</cfoutput><br>
    <cfset i = i + 1>
    </cfloop>

  • How do I insert an image with my signature but without URL?

    Although there are several Firefox users in my unit with the same version of Zimbra, some have an "insert image" but mine and some others have only "insert image URL" in the signature area. the people with the insert image icon have no problems adding a company logo but I cannot.
    Thanks for any help.

    Is that Comcast web-mail with Zimbra?
    If so, are you using HTML format or Text format when composing emails?
    ''Look in Email Preferences to see that setting under Composing to see.''

  • Another BC Question (Installing Windows WITHOUT Boot Camp)

    Is it possible (and/or even advisable) to install Windows on my second internal without Boot Camp? (i.e. reformatting the entire drive as one Master Boot Record Partition, then boot and install from Windows disc directly)?
    If so, are there instructions for doing this anywhere? or would i just do it the same way i would install a new Mac OS from cd (more or less).
    After that, would I insert Leopard CD and install drivers as usual?
    If done this way, would there still be a way to boot back to Mac OS from windows? or would i have to do the option key at start up process each time?
    No other reason than that I'd like them each on their own drive.
    I will likely install Vista, but might wait to buy 7, if that matters. Primarily for games.
    Thanks again.

    I'm interested in this as well and tried it out on my mid-2009 macbook pro using the following instructions:
    http://derekhat.com/install-vista-on-a-macbook-without-bootcamp/
    I haven't gotten the drivers to work out nicely (eject, function keys, delete, trackpad scrolling/rt-click) don't work yet but things work for the most part. I tried to find the drivers by navigating through the Max OSX disk (Windows couldn't find all the drivers even though I guided it through all the available folders) and also by running Boot Camp (errors didn't let me install it).
    I'm interested in learning more if anyone has gotten further.

Maybe you are looking for

  • HP Laserjet 1018 does not print (Vista)

    Hi, I've had the HP Laserjet 1018 for about 2 years and have been a very happy customer. Recently I upgraded to Windows 7 and have been using it without trouble for a few months. Just a few days ago I started having some spooler problems on Windows 7

  • What are the chances of me getting approved for financing for a Macbook with no credit at all?

    I don't have bad credit. I have no credit. I make an okay amount of money annually. Not bad for having no rent or bills over 50$ to pay for. I applied this morning for financing cause I need one for school and it said I'd get a letter in 7-10 days..

  • Link on a flash banner

    Hello ! As a beginner at Flash, I encounter my first difficulty ... I want to create a banner, linked on all its surface to an Url. I created a transparent button on a special layer a the top, and converted it as a button, before applying it the "cli

  • Lost all files and applications installed after changing user profile in the registry of windows 8.1 pc

    The original user profile on my windows 8.1 pc is C:\Apple\acer sm. I tried changing it to C:\Apple\Apple. After I rebooted my PC, I found out that all my files and applications are lost. What shall I do to recover them? Your help would save my life.

  • Opening .tif files

    When I try to download & open a .tif (image) file, my Mac automatically uses QuickTime to open the file. How do I change it to open in Preview instead? (I want .tif files to work the same way as .jpg files on my Mac.)