JTextPane hyperlink color

Hi there,
this is an easy one, I reckon... haven't found a solution yet, though:
How do you change the color of a hyperlink when displaying HTML in a JTextPane?
Neither the link, vlink etc. <body> tags, nor the corresponding CSS attributes (a:link {color: #foobar;} etc.) lead to the desired effect. Funny enought, setting things like hyperlink font style seem to work using the latter method!
Any idea?

Hi,
You say you have tried to set the foreground color in the attributeset and it didn't work. Are you sure you did this coreectly.
This is how I trid and it worked for me.
        SimpleAttributeSet attr2 = new SimpleAttributeSet();
        attr2.addAttribute(StyleConstants.NameAttribute, HTML.Tag.A);
        attr2.addAttribute(HTML.Attribute.HREF, s);
        StyleConstants.setForeground(attr2,Color.blue);
        StyleConstants.setUnderline(attr2, true);
        setAttributeSet(attr2, false);
        m_doc.insertString(m_doc.getLength(), s, attr2);

Similar Messages

  • JTextPane Hyperlink Functionality Help Required

    Hello there,
    I am using the JTextPane in my Java Swing Application. How do I make it Handle Hypelinks. Like lets say the use enters
    \\some_foldername\some_subfolder_foldername\some_file.xls or any other file type, It should Automatically, treat it as a hyperlink.
    Is it Possible to have such a functionlaity
    JTextPane Hyperlink Functionality
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextPane;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    public class TextSamplerDemo extends JPanel {
         public TextSamplerDemo() {
              setLayout(new BorderLayout());
              // Create a text pane.
              JTextPane textPane = new JTextPane();
              setPreferredSize(new Dimension(250, 155));
              setMinimumSize(new Dimension(10, 10));
              // Put everything together.
              add(textPane, BorderLayout.LINE_START);
         private static void createAndShowGUI() {
              JFrame frame = new JFrame("Hyperlinks in Java Editors");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.add(new TextSamplerDemo());
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        UIManager.put("swing.boldMetal", Boolean.FALSE);
                        createAndShowGUI();
    }Regards,
    Hemanth

    Try something along these line
    1. get start and end off highlighted text
    2. replace highlighted text with a string builder or something similar
    <html><FONT COLOR=BLUE> <u> TEXT</FONT></u>
    Calypso
    Edited by: calypso on May 15, 2009 4:42 AM
    On second thought I think you can shorten that to
    <html>TEXT

  • Hyperlink Colors

    We are experiencing a minor problem with hyperlink colors, specifically "visited" hyperlinks. The color is not changing. I have checked the browser and the settings are set to colors for the visited and unvisited links.
    Is this setting controlled anywhere in the Web Server?
    Jeff

    No, Web Server has no control the colour of hyperlinks. The colour for visited links can be controlled by style sheets and/or HTML attributes; check the HTML source and any associated style sheets.

  • Hyperlink color and publishing wierdness

    I've used the tutorial at 11Mystics to change hyperlink colors in my blog templates and in the existing pages. In each case, I made the changes one at a time and then checked in iWeb to make sure they worked. Every page displayed in iWeb exactly as I wanted.
    Then I published all to .Mac. Viewing the blog entries in Safari, some of the links appeared blue while others were still the default gray. In at least two blog entries this is true within a page - some are blue some are gray. I tried recreating those pages thinking that the newly edited template would fix it. Again, in iWeb everything appeared fine but in Safari the same result. I cleared the Safari cache and relaunched with no change.
    Then it occured to me to check in Firefox. There all of the links are perfect. If this was as far as it went I'd attribute it to Safari problems. But I also checked using Firefox on my office PC and there most of the links are correct but a couple are still gray. So that is three different results. I'm very perplexed. The only thing I can think of is that in the two browsers where it isn't quite right, I've viewed some of these pages before whereas in Firefox on my Mac I hadn't (I rarely use Firefox on the Mac). On the PC and in Safari I've cleared the cache so I don't see why previous viewing would be an issue.
    In case anyone wants to have a look:
    http://web.mac.com/dmath/iWeb/Woodworking/Blog/Blog.html
    Choose the top entry. There should be three blue links. In Safari on my iBook only the first one (Bridge City Tool Works) is blue.
    I'd appreciate any help with this. Thanks.
    David
    Message was edited by: dmath

    More information: I just tried it on my kids' Mac Mini running an old version of Safari. All of the links display perfectly. It must be a cache issue. I'll have a look around on the Safari discussion board to see if I can find anything.
    David

  • Hyperlink color

    Is ther a way to change the hyperlink color? I created a new hyperlink style but when I enable the hyperlink, it pops back to the orinal color (red!).
    Please help.

    See that topic in iBA Tips and Tricks 01

  • Hyperlink color doesn't change when hovering over link

    I create hyperlink, color I select for hovering over link works fine. But sometimes when I publish to my website the link color does not change, but the link works ok. I go back to my mac and check, sure enough the color changes just fine. I wipe out the link and reinsert new one. Works fine on the mac, but when I publish, color does not change when hovering. Help.

    Welcome to the discussions. This is a long shot, but try clearing your browser's cache and reloading the page — then see if the color changes when hovering. ( In Safari, click on the Safari menu and choose +Empty Cache...+ )

  • New Hyperlink Color

    I am having trouble changing a hyperlink color.
    My default is red and I wwant it to be blue.
    I create a new hyperlink, modify the font, size, and color as I want.
    I "Create Character Style From Selection".
    When I use Link Inspector - Enable as a hyperlink - email, it changes font and size, but not color.
    The default red is always used.
    This happens if I make the text a link first or if I make the changes first and then make it a link.
    What am I doing wrong?
    Default:  My Hyperlink
    Desire:   My Hyperlink
    Muchas Gracias

    Here is how a new Hyperlink 2 looks on my iMac in iBooks Author:
    The Character Style is blue, but the text stays red. And here it is on my iPad:
    Hard to see, but it is in blue as it should be.
    So why do my efforst to modify show up correctly on the Mac?

  • Hyperlink color not showing up

    I can get the hyperlink to be a color when I'm editing/composing a blog entry; but when I publish it, it looks black until you roll over it. You can't even tell it's a hyperlink unless you would accidentally roll over it. What am I doing wrong?

    I'm having the same problem with hyperlink colors viewed in Safari 3.1.2, whether Normal or Rollover Format. Firefox 3.0.1 displays the colors as formatted in iWeb. I was having this issue prior to and still with iWeb 2.0.4. Click here to see what I mean and look at the links in the text box. I have the Normal color set to Midnight and the Rollover color set to Steel in iWeb.
    Update; Actually, Firefox is not displaying the colors 100% either. At the bottom of the text box where it says photo gallery and resume, photo gallery is not in the Midnight color.

  • How to make selected text in a JTextPane HyperLink

    Hi guys,
    I am trying to Hyperlink the displayed text in JTextPane but its not occuring.Does anybody has some suggestion.I am posting the part of my code which i was using to hyperlink the given text but its not working....Plz give some suggestions regarding this....
    public void addHyperLink()
    Document doc;
    URL url=null;
    try {
    url = new URL("http://www.gmail.com");
    } catch (MalformedURLException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    SimpleAttributeSet attributeSet= new SimpleAttributeSet();
    attributeSet.addAttribute(HTML.Attribute.HREF, url.toString());
    SimpleAttributeSet attributeSet1= new SimpleAttributeSet();
    attributeSet1.addAttribute(HTML.Tag.A,attributeSet);
    String text=pane.getText(); // pane is instance of JTextPane
    try {
    doc=pane.getDocument();
    doc.insertString(0,text,attributeSet1);
    } catch (BadLocationException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }

    Search the forum this question is asked a lot. Also if you post code please post a Short,Self Contained, Compilable and Executable, Example Program and use code format tags.

  • Set Default Hyperlink Color

    How can I set a different default color for hyperlinks in Pages?
    My company's style sheet dictates a particular color for hyperlinks; I'd like to be able to set that once rather than having to manually set the color each time.

    Kuro Rai wrote:
    I know for a fact that there is a way to change the default colour of a hyperlink.
    It doesn't work for me. I don't see a hyperlink style already set up, and while I can create one, it isn't used by default.
    I produce a weekly newsletter that is mostly distributed on paper, and so printed in black and white. I also want to get rid of underlining. And every time, I add an email address or a URL I've got to manually select it, set the color to black and turn off underlining. The style really should be user controllable.

  • Changing hyperlink color and format in numbers 3

    Hi all!
    I want to change the automated color (and format: underline etc.) that is assigned to hyperlinks.
    In my file I use vlookup to get the email and webadresses from a different source table. In the source table, I've tried disabling the hyperlinks and give different colors. In the destination table (different sheet), it keeps reformatting the @'s and www to hyperlinks. Smart link substitutions are off..
    Manually changing the text color in the destination cell doesn't work, probably because of the vlookup formula?
    hope you guys can help me out, thnx in advance!

    Hi Eliakim,
    Turning off Smart Link Substitutions does not 'kill' existing active hyperlinks. It prevents the automatic conversion of an address that is subsequently typed or pasted.
    I pasted an active hyperlink into a Numbers cell, and it remained active even though Smart Link Substitutions was off.
    When I did Menu > Edit > Paste And Match Style the hyperlink was not active.
    Try this. In your source table, select and copy the hyperlinks. While they are still selected, Paste And Match Style. They will still appear to be hyperlinks (blue text underlined) but will be inactive (I assume that is what you want).
    See what that does to the text inserted by vlookup in your destination table.
    Regards,
    Ian.

  • Can't format Hyperlink Colors

    Hey,
    For some reason, the Format tab for my hyperlinks are grayed out and won't let me select a rollover color. I am selecting the text, selecting enable as hyperlink, deselecting Make hyperlinks active so I can edit the text, but when I go to the format tab to change the rollover colors, the options are grayed out.
    What could I be missing? This seems very straight forward.
    Thanks,
    Wes

    It also depends on what hyperlinks you are trying to format as to whether this will work in the first place though? Are you trying to format nav bar links? If so, this won't work, because you can't do it, so it will be grayed out. You can't format the nav bar templates. If you want to do this, go to Inspector and hide it and make your own that you can use hyperlink format.

  • Make whole Text clickable (or change Hyperlink color)

    Dear madams and sirs,
    the issue is the following: I have some text that needs to respond to MouseClicked.
    This text NEEDS to be orange - that's why i use a Text control.
    Problem: it only catches a click on the strokes and not inbetween.
    Possible solution: Use a Hyperlink control. But I cannot work out how to change it's color to orange.
    So how on earth can I either make the whole Text clickable
    OR change the color of the Hyperlink (any other way apart from css?) ?
    p.s.
    is it possible here to confine the search to specific forums?

    After hours I finally found a way to work myself around these two still unsolved questions:
    instead of the Hyperlink or Text simply take a Label, insert text, give it a color
    and put a transparent Rect on top of it. The Rect does the mouse listening.
    so another question arises:
    Why does the Label not respond to any mouse event? In my case it did not even support the change of cursors?

  • Having trouble changing hyperlink color

    Hey everyone. I've been working on customizing one of the default themes and I can't seem to change the color of the hyperlinks to better suit my page. The desired color only shows up when I put the mouse over the hyperlink itself, rather than being displayed as that color without being indicated. The color it is looks particularly awful with my page, so I'd really appreciate some help. Thanks.
      Mac OS X (10.4.8)  

    Have you seen this resource page from Michael Wong? It might provide some hints to you. I don't know if you are trying to edit the xml or just the published css, though.
    http://www.rowan-cottage.co.uk/Site/CSS%20in%20iWeb.html
    Anyways, it looks like the hyperlinks have 3 distinct states: unvisited, rollover, and visited, and the one it sounds like you want to edit is the unvisited state.

  • Changing hyperlink color

    I've put a hyperlink on a blue background and want to make it white instead. I cannot figure out how to do this. (I do know how to change colors of everything else.)

    I recently discovered how to do this in iWeb & thought it might work the same in Pages. It doesn't, but I actually discovered it is easier. Select the text of the hyperlink & change the color of the text using the box on the format bar or the text inspector.

Maybe you are looking for

  • Unable to load Driver Class

    Hi There: When I try to connect to the Oracle 8i via this applet , I get the following run time error. Any help will be appreciated. I am using j2sdkee1.3.1, jdk1.3.1_02 and Oracle8. I also need your suggestion please. I have inserted some BLOB data

  • Text issues in Mail 1.3.11

    Hello, I just set up my mail program for the first time. It works great but I'm having a tough time with composing. When I type something it comes out incorrect. For example when I type "a" I get an "o" on my screen. I noticed the same problem with s

  • Can we pass values to custom headers through HTTP bindings in BPEL?

    hi, I have an urgent requirement where I have to pass values to custom headers of HTTP url through HTTP bindings in bPEL. Is it possible? Say I have a http url http://localhost:80/test. I need to post xml over the above HTTP url as well pass some val

  • Upgrading and ADF appplication

    my case is that i have an ADF application developed on JDEV 10.3.1.0 and upgraded it to JDEV 10.3.1.2, it's works fine on the embedded OC4J for the JDEV but on the AS it's gives page not found error after the login page although my AS OC4J is compati

  • Conditional Printing when NE to 0

    Post Author: LaVerne CA Forum: Formula Good Morning - I would like to suppress printing of records when (the Actual Volume = 0 and the Budgeted Volume = 0).  Amounts in either of these field can be less than 0 in which case, I would like the row to p