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.

Similar Messages

  • How to set selected text on JTextPane ?

    I need to set selected text on a JTextPane. I used setSelectionStart(); and setSelectionEnd(); but it doesn't work.
    Can anybody help me?

    I'm not sure if this is what you are looking for, but the following code sample was revised from the tutorial TextSamplerDemo.java. It will hightlight the word "selected" in yellow in the JTextPane.
    //created with j2sdk1.4.0_01
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;      
    public class SelectedText extends JFrame {
        public SelectedText() {
            super("Selected Text");       
            //Create a text pane.
            JTextPane textPane = createTextPane();
            JScrollPane paneScrollPane = new JScrollPane(textPane);
            paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
            paneScrollPane.setPreferredSize(new Dimension(250, 155));
            paneScrollPane.setMinimumSize(new Dimension(10, 10));
            Container pane = getContentPane();
            pane.add(paneScrollPane);
        private JTextPane createTextPane() {
            JTextPane textPane = new JTextPane();
            String[] initString =
                    { "This is the ", //regular
                      "selected",     //selected
                      " text. "       //regular
            String[] initStyles = {"regular", "selected", "regular"};
            initStylesForTextPane(textPane);
            Document doc = textPane.getDocument();
            try {
                for (int i=0; i < initString.length; i++) {
                    doc.insertString(doc.getLength(), initString,
    textPane.getStyle(initStyles[i]));
    } catch (BadLocationException ble) {
    System.err.println("Couldn't insert initial text.");
    return textPane;
    protected void initStylesForTextPane(JTextPane textPane) {
    //Initialize some styles.
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
    Style regular = textPane.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "SansSerif");
    Style s = textPane.addStyle("selected", regular);
    StyleConstants.setBackground(s, Color.YELLOW);
    public static void main(String[] args) {
    JFrame frame = new SelectedText();
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    frame.pack();
    frame.setVisible(true);
    S.L.

  • I cannot figure out how to make the text larger on an incoming email.  The finger method doesn't work and I cannot find any toolbar with which to do it.  I could find nothing in settings also.  Plese help and thank you.

    I cannot figure out how to make the text larger in a received email.  The finger method doesn't work and I can find no tool bar as I can for composing emails.  I can find nothing in settings.  Please help and thank you in advance.

    Hi there,
    Download a piece of software called TinkerTool - that might just solve your problem. I have used it myself to change the system fonts on my iMac. It is software and not an app.
    Good wishes,
    John.

  • How to make a text "drawer" in iWeb

    Does anyone know how to make a text "drawer" in iWeb? What I mean is when you click on a hyperlink to read more text, but instead of opening up a new page, it makes the text appear below the link on the same page.

    Anything fancy with iWeb has to be done in the HTML Snippet or after publishing the page.
    Find the code for the drawer, apply it and show us the result.
    Perhaps not the drawer you had in mind but this is something near:
    http://www.wyodor.net/Ajax/
    Here's another one with drawer in the title:
    http://jqueryfordesigners.com/slide-out-and-drawer-effect/
    http://jqueryfordesigners.com/demo/plugin-slide-demo.html
    Found with : [text drawer|http://www.google.com/search?client=safari&rls=en&q=text+drawer&ie=UTF-8 &oe=UTF-8]

  • How to make the text in sub-division

    Hi,
    I am usign text  module in my adobe forms.
    Text in text module contains sub-divisions as a), b) and c). Each sub-division are in a separate line.
    While in pdf, all the sub-division combines and comes a single paragraph.
    What  would be the problem for this issue? Any Idea?
    May I know how to make the text in sub-division as in text  module?
    Thanks,
    Thiyagu
    Edited by: Thiyagu on Oct 26, 2009 7:08 PM

    Hello, experiment with Object - Field tab. Do you have your text field with "allow multiple lines" checked? I guess so. And what about the field format? Plain text or Rich text? Please try:)) Regards, Otto

  • How to make indented text in Muse

    How to: make indented text in Muse, like a list with bullits

    I read on another post that you can do ALT 0149 (WIN) and it will create a bullet in Muse.  I tried ALT+0149 and then ALT then 0149 and neither one created a bullet so I must not be understanding the key shortcuts to create the bullet.
    The above video is not captioned (I'm deaf) so I don't understand how he's creating the bullets.  Can someone explain what I'm doing wrong?
    PS - when videos are made, it would be nice if you brought some kind of graphic on saying (for example) "Press the [whatever] key" so deaf people can see what's happening.

  • How do make the text on a label Bold?

    Simple question: How do make the text on a label Bold?

    use html : label.setText("<html><body><b>TestText</b></body>/html>");
    regards,
    Tim

  • How to programatically select text for editing in an af:inputText control?

    Hello, I am new to jdeveloper 11.1.1.3.0 and have searched and searched for info. I must be using the wrong terms as I cannot find any info or example on how to programatically select text for editing in an inputText field.
    My request is to change an existing app so when the user presses a button, control should go to the inputText control (this part works, see existing backing bean code from another developer below) but automatically select the text within for editing by the user (saving the user from having to select the text first before editing).
    Backing bean code to set the focus to an inputText field:
    * sets the cursor to the given component id
    * @param  componentId of item on page
      public void setFocusOnUIComponent(String componentId) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExtendedRenderKitService service =
          Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
        UIComponent uiComponent = facesContext.getViewRoot().findComponent(componentId);
        service.addScript(facesContext,
          "Component = AdfPage.PAGE.findComponentByAbsoluteId('" + componentId + "'); Component.focus();");
      } I hope this isn't a dumb question and would appreciate it if someone can steer me in the right direction.
    Thank you for any info,
    Gary

    Hi,
    not a dumb question at all. Before answering it, here some comments on the code you pasted in your question
    1. UIComponent uiComponent = facesContext.getViewRoot().findComponent(componentId);
    This code line is not used at all in your method. So it seems you can get rid of it
    2. "Component = AdfPage.PAGE.findComponentByAbsoluteId('" + componentId + "'); Component.focus();");
    I suggest to change it to
    "var component = AdfPage.PAGE.findComponentByAbsoluteId('" + componentId + "'); component.focus();");
    as it is better coding practice to have variable names starting with a lower case letter and being flagged with the "var" identifier
    For pre-selecting text in an an input component, there is no API available in ADF Faces, which means you need to reach out to the rendered HTML ouput. To access the markup for the rendered component, you can try
    var markup = AdfRichUIPeer.getDomContentElementForComponent(component)
    If this markup returns the HTML input component then you can use JavaScript you find on the Internet to select the area of it. If it does not return the input component then you may have to use
    document.getElementById(componentId+'::content')
    Note however that working directly with generated HTML output bears the risk that your code breaks when - for whatever reason - the ADF Faces component rendering changes in the future
    Frank
    Frank

  • Anyone know how to make vertical text in a table in keynote?

    anyone know how to make vertical text in a table in keynote?

    Just to add a bit more about this question. I have seen in other related questions that this feature (vertical text) is not available in (apparently) the whole iWork09. someone even said that it should be asked to the developers, so they include this feature in iWork10. I find this issue a bit sad. This feature has been present in msOffice since a while, and at least for me, this is quite important for my work. It is also apparently not possible to have different page orientation in the same document, meaning portrait and landscape, so one can have wide tables in a whole page, for example. If this is true, it is again sad, and I just cannot understand why such a basic feature is not available in an already 09 version. I am using only the trial version of iWork, but already in the first day I have discovered that I actually cannot do what I was used to. Again sadly I (and many others I guess) will have to stick to Office until the mac software is fully developed.

  • Help:How to make static text in JTextField??

    How to make a text to be displayed initially on a JTextField, yet we can not change the text (so the text
    is static)?
    The other question:
    How to make an input mask so that a JTextField
    has input pattern of XXX.XXX.XXX.XXX
    (which is the mask of IP Address) ??
    What I know that limiting input in JTextField can be done
    by extending PlainDocument....what about the cases above??
    Please reply if you know.
    Thanks a lot,
    Ted.

    For the first question, just call setEditable(false).

  • How do I select texte discontinuouly : one word here and another there

    How do I select texte discontinuouly : one word here and another there, etc.

    Use Pages '09.
    Feature has been removed from Pages 5, along with 100+ others.
    Peter

  • How to get selected text values in a textarea by mouse click?

    Hi Everyone,
    What I am trying to do is to click on some texts in a textarea, then get the selected text value.
    If you guys have used an accounting software called Simply Accounting, you might understand better.
    I list all my customer names in a textarea. What I want is, when I click on one customer, another GUI pops up with this customer's information. My problem is that I don't know how to get the selected text value from a textarea.
    Could anyone give a hand here? Thank you in advance.

    Is there some reason you aren't using a JList or
    JTable to display
    the user names/information?Thank you for es5f2000's reply. You just gave me a better idea! There is not a particular reason I have to use TextArea to list my customers. As long as the component can make my idea alive, I definitely use it. Still, if there is any way to get a selected text value, it will help me a lot with my project. Thank you.

  • How to make select list as read only

    Hi All.
    when i m loading a page ...how to make value of select list as read only ..
    i tried doing this ....
    i added readonly attribute to the select list's element attibute ...it is showing as read only field by darkening the select list field but ... the select list is editable even now... its allowing to choose from drag and drop ...
    Thanks & Regard ,
    Nandini

    I have the same requirment..
    I have a select list on a editable form and i want to make that one read only.
    When I use read only property it doent do anything. (But this is working for text items well).
    When I use "disabled' option it works fine. But then that value does not post when use POST the form. So making select list disabled is not a solution.
    Any Idea..
    Thanks
    mc

  • How to set selected text color in Spark TextInput

    I'm trying to make Spark TextInputs and MXFTETextInputs look like Halo/MX TextInputs as much as possible, since I have a mix of both Spark and MX TextInputs in my application. I know I can set the
    selection background color to black using focusedTextSelectionColor. How can I set the selected text color to white so it matches the MX white-on-black look?

    This works, if you set the enabled property directly on the s:TextInput:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx">
        <s:layout>
            <s:VerticalLayout horizontalAlign="center" verticalAlign="middle" />
        </s:layout>
        <s:controlBarContent>
            <s:CheckBox id="ch" label="enabled" selected="true" />
        </s:controlBarContent>
        <fx:Style>
            @namespace s "library://ns.adobe.com/flex/spark";
            @namespace mx "library://ns.adobe.com/flex/mx";
            s|TextInput:disabled {
                color: red;
        </fx:Style>
        <s:Group>
            <s:TextInput id="ti" text="The quick brown fox jumps over the lazy dog" enabled="{ch.selected}" />
        </s:Group>
    </s:Application>
    It can get a bit trickier when you're setting the enabled property on a parent container, since (I believe) that the child control's enabled properties are still set to true and just the container is disabled. One possible workaround would be to bind the child TextInput control's enabled property to the container's enabled property. That way the s:TextInput should still go to it's disabled state and you can customize the disabled state's styles to have darker text, or whatever else you want.
    <s:Group id="gr" enabled="{ch.selected}">
        <s:TextInput id="ti" text="The quick brown fox jumps over the lazy dog" enabled="{gr.enabled}" />
    </s:Group>
    Peter

  • How to make selected and active a child row of a treeTable?

    Hello,
    I am inserting a new child row into a af:treeTable, disclosing it, but I can't figure out how to make it selected and active so the focus of the user to go on it.
    Jdeveloper version 11.1.2.3.0
    This is how I am inserting the child node:
    public void createLocation(RowIterator ri, Key selectedNodeKey) {
            final String locationCategoryViewDef = "model.views.LocationCategoryView";
            if (ri != null && selectedNodeKey != null) {
                Row[] found = ri.findByKey(selectedNodeKey, 1);
                if (found != null && found.length == 1) {
                    Row foundRow = found[0];
                    String nodeDefname = foundRow.getStructureDef().getDefFullName();
                    RowSet parents = (RowSet)foundRow.getAttribute("LocationView");
                    Row childrow = parents.createRow();
                    //hardcoded locationId
                    childrow.setAttribute("LocationId", 434558);
                    parents.insertRow(childrow);
    }  And this is the treeTable:
    <af:treeTable value="#{bindings.LocationCategoryView2.treeModel}" var="node" varStatus="vaarr"
                  partialTriggers="gaga gag4a ga4a"
                  selectionListener="#{bindings.LocationCategoryView2.treeModel.makeCurrent}"
                  displayRow="selected" rowSelection="single" id="tt1" editingMode="clickToEdit"
                  horizontalGridVisible="true" binding="#{pageFlowScope.treeTableBean.sampleTreeTable}">
        <f:facet name="nodeStamp">
            <af:column id="c5" width="15">
                <af:outputText value="#{node}" inlineStyle="display:none" id="ot1"/>
            </af:column>
        </f:facet>
        <f:facet name="pathStamp">
            <af:inputText value="#{node}" id="ot2"/>
        </f:facet>
        <af:column id="c2" headerText="Location CategoryName">
            <af:inputText value="#{node.LocationCategoryName}" inlineStyle="font-weight:900" id="ot45"/>
        </af:column>
        <af:column id="c6" headerText="Location CATID">
            <af:inputText value="#{node.LocationCategoryId}" inlineStyle="font-weight:900" id="ot6"/>
        </af:column>
        <af:column id="cgg2" headerText="Var INDEx">
            <af:outputText value="#{vaarr.index}"/>
        </af:column>
        <af:column id="c1" headerText="Location Name">
            <af:inputText value="#{node.LocationName}" id="ot3"/>
        </af:column>
        <af:column>
            <af:panelGroupLayout layout="vertical">
                <af:commandLink id="gaga" text="addLocation" inlineStyle="color:red"
                                action="#{pageFlowScope.treeTableBean.createChildren}"
                                rendered="#{node.LocationId == null}" partialSubmit="true"/>
                <af:commandLink id="gag4a" text="delete category" inlineStyle="color:blue"
                                partialSubmit="true" rendered="#{node.LocationId == null}"
                                action="#{pageFlowScope.treeTableBean.deleteChildRow}"/>
                <af:commandLink id="ga4a" text="delete location" inlineStyle="color:green"
                                partialSubmit="true" rendered="#{node.LocationId != null}"
                                action="#{pageFlowScope.treeTableBean.deleteChildRow}"/>
            </af:panelGroupLayout>
        </af:column>
    </af:treeTable>

    Yes I did now but nothing changes. The current, selected and active row is still the parent node...
    Even I am adding AdfFacesContext.getCurrentInstance().addPartialTarget(this.sampleTreeTable); for just in case..

Maybe you are looking for