Results 1 to 3 of 3
  1. #1
    Pain is offline Member
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Default replacing text in jTextArea by image

    i'm supposed to read text from a jtextarea, compare if any characters correspond to those in an array, no prob here but i'm having hard time to append a image to a particular set of characters. I mean after having found them in the jtextarea use jtextarea's replacerange to do the job, but as this function replaces some string by another string, i tried using html in the first parameter to load it in it. Example:
    Java Code:
    jTextArea3.replaceRange("<IMG SRC=\""+WINK +"\">", text.length()-1, text.length());
    where WINK is
    Java Code:
    final String WINK = ClassLoader.getSystemClassLoader().getResource("images/3.gif").toString();
    i've seen others do it this way, but i doesn't seem to work for me.
    i tried using jtextpane but i can't find how to replace text at a particular index with an image.
    So my question would be. Does anyone know how to append text at a partcular index in the jtextarea so as to replace it by an image.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Using a JTextPane you can add an image using the insertIcon(...) methd.

  3. #3
    Pain is offline Member
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Default

    well, i need to replace a substring by an image, and to to that i need to get the index of the start of that text and then replace it according the the obtained index, i don't think that jtextpane's inserticon() has this facility(of course i could be really wrong). If a piece of text can be replaced by inserticon() then can someone give an example, or direct me to it, the examples i've seen are not quite understandable and i don't even know if it can be achieved using jtextpane till now

Similar Threads

  1. Printing text files to a JTextArea
    By Adrien in forum AWT / Swing
    Replies: 11
    Last Post: 02-23-2010, 04:45 PM
  2. Replies: 13
    Last Post: 12-11-2009, 09:43 AM
  3. Need Help showing text in JTextArea
    By GuyFawkes in forum AWT / Swing
    Replies: 3
    Last Post: 05-05-2008, 10:19 AM
  4. JTextArea - text align
    By bradder in forum AWT / Swing
    Replies: 1
    Last Post: 11-29-2007, 08:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •