Highlighting text in JEditorPane using HTMLEditorPane

I am using JEditorPane extending HTMLEditorkit. In the HTMLEditorkit when we use the span tag for highlighting the text of a line, it is just not showing it. It starts the color and ends it there and then. It looks like a small dot and doesnot spans the whole line.
Is this a bug or something in JAVA 1.3.1. If anyone of you knows how to do it please let me know.
I need it for a project which has a deadline.
Thanks.

JEditorPane is not rendering and HTMLDocument.HTMLReader is not reading the SPAN tag. In other words, the SPAN tag is not supported in Java. You can still use it by overriding the mentioned classes. My application SimplyHTML gives an example of how this can be done. Please visit http://www.lightdev.com/dev/sh.htm
Ulrich

Similar Messages

  • Finding highlighted text in Pages using Applescript

    Hi guys, I'm writing a script that will parse through a Pages document and retun me the indices of the first and last characters of each block of text which is highlighted with a given colour. I do have a script that works, the only problem is it runs very slowly.
    Here's what I have at the moment:
    tell application "Pages"
              tell front document
      --colour to test for in RGB (0 to 65535)
                        set testColour to {65535, 0, 65535}
                        set lastCharColour to missing value
                        set N to (count of characters)
                        set indexArray to {}
                        repeat with i from 1 to N
                                  set thisCharColour to character background color of character i
      --add the character if it is highlighted
      --and the previous one wasn't
                                  if thisCharColour is testColour and lastCharColour is not testColour then
                                            set end of indexArray to i
      --or add the previous one if this one is
      --not highlighted and the previous one was
                                  else if thisCharColour is not testColour and lastCharColour is testColour then
                                            set end of indexArray to (i - 1)
                                  end if
      --update the previous character's colour
                                  set lastCharColour to thisCharColour
                        end repeat
      --if there are an odd number in the list,
      --the document must end with a highlight,
      --so we'll add the last character
                        if ((count of indexArray) mod 2) = 1 then
                                  set end of indexArray to N
                        end if
                        get indexArray
              end tell
    end tell
    I'm parsing over every character in the document, and adding the index to a list if its background has changed colour either to or from the specified colour. It seems to be that the "get character background color of character i" call inside the loop is what's taking a long time. I have tried caching off a list of all the colours as a first step and then just comparing against an item in that list, but it's not significantly faster (in fact it might even be slower, I aborted it because it was taking too long).
    I know in MS Word it is possible to do a find operation to find characters which are highlighted in a particular colour, so I was sondering if it was possible to do something similar in Pages, or can anybody think of a way to streamline my logic here?
    Thanks,
    Andy

    However, I've just realised, my reason for getting the character indices was so as I could, in a subsequent step, get the characters themselves. I can modify your script to get the actual characters as well as the character offsets, and then where there's a break in the character offsets I can split the characters into substrings, as below:
    set theBackgroundColor to {0, 65535, 0}
    getCharIndex(theBackgroundColor)
    on getCharIndex(bgColor)
              script o
                        property myList : {}
                        property charList : {}
              end script
              tell application "Pages" to tell front document
                        set o's myList to character offset of (characters whose its character background color is bgColor)
                        set o's charList to (characters whose its character background color is bgColor)
              end tell
              set tc to count o's myList
              if tc = 0 then return {}
              set i to 1
              set blockArray to {}
              set lastBlockEnd to 0
              repeat while i < tc
                        set N to item i of o's myList
                        repeat with J from (i + 1) to tc
                                  set N to N + 1
                                  set n1 to item J of o's myList
                                  if N is not n1 then
                                            set end of blockArray to ((items i thru (J - 1) of o's charList) as text)
                                            set lastBlockEnd to (J - 1)
                                            exit repeat
                                  end if
                        end repeat
                        set i to J
              end repeat
              set end of blockArray to ((items (lastBlockEnd + 1) thru tc of o's charList) as text)
      return blockArray
    end getCharIndex
    This has all your speed advantages, and still gets me the end result I'm after.

  • How Do highlight text in the body of an email message in Mac Mail?

    Can anyone tell if IF and HOW I can highlight text in the body of an email message using Mac Mail (in Yosemite).  I do NOT mean MARKUP an attachment.  I want to highlight a word or phrase in the body of my email message.  I know I can change the font color, but can't seem to add a highlight!  Thanks!

    Hi,
    is is possible, - link is below. Works on Yosemite, btw.
    http://www.mihalick.us/how-to-highlight-text-in-yellow-using-apple-mail/

  • JEditorPane - backmapping highlighted text to source html document

    Hello everyone,
    I have the following problem: I display a HTML document in JEditorPane. Then I highlight some chunk of text and get the start and the end selection offsets by using getSelectionStart() and getSelectionEnd() methods, respectively. What I would like to know is the exact position (character offset) of the highlighted text in the original HTML document that is being displayed.
    Does anybody know the solution for that?
    Thanks.

    I don't think it's possible. The parser builds a Document out of the text and doesn't keep the original source text. For example if your html is like this:
    String text = "<html><body>     some     text     </body></html>";All the multiple spaces between the text is parsed out.
    Use a JTextPane and use attributes. Its easier to work with than using HTML.

  • Highlighting Text in pdf Documents using Preview

    Am using Snow Leopard (10.6.3) with Preview version 5.0.2.
    Tried highlighting text using the instructions in Preview help. No success.
    I click Annotate; chose the Highlight Colour but then appear to be unable to select the text.
    Anyone any ideas?
    Thanks

    Thanks for the hint. I think I've just discovered why I cannot do it. The pdf document I'm trying to highlight is the result of the output from a scanner. Hence it is effectively a "picture" - not text. The only thing that I have been able to do is to choose Annotate and then choose "Add Oval" or whatever and select its size and colour and then position this over the text I wish to highlight.
    Because it is effectively a picture you cannot select text. I tried it on another pdf document that IS text and your solution works a treat.
    Thanks again
    Malcolm

  • Changing highlight text color / using Highlighters

    I've subclassed JTextArea, and among other things, am trying to add the functionality for drawing the active selection even when the TextArea doesn't have focus. I've overridden processFocusEvent like so:
    public void processFocusEvent(FocusEvent e){
            Highlighter h = this.getHighlighter();
             if (e.getID() == e.FOCUS_GAINED){
                //remove the inactive highlight
                h.removeAllHighlights();
            //this will put the selection highlight back in for us, among other things,
            //if we just gained focus.
            super.processFocusEvent(e);
            //now add the inactive-selection highlight if we just lost focus
            if (e.getID() == e.FOCUS_LOST){
                try {
                    h.addHighlight(
                            this.getSelectionStart(),
                            this.getSelectionEnd(),
                            new DefaultHighlighter.DefaultHighlightPainter(
                                new Color(212,212,212)
                } catch (Exception ex){
                    ex.printStackTrace();
        }and it works quite nicely. Notice that I draw the inactive selection gray.
    There's a slight problem with this: JTextArea doesn't treat the text in the highlighted section any differently, as opposed to how it would when the component is focused (i.e. rendering it in the highlighted text color). I'm guessing this is because it knows that it's not focused, and therefore assumes that there's no highlighting to be drawn. So as a result, all text in the text area is rendered in the same color --- the foreground color --- when the textArea doesn't have focus, regardless of what is being highlighted. For this reason, setSelectedTextColor() has no effect.
    But I want to be able to change the highlighted text color, since, in theory, the user's system could be configured to show text in the exact same gray that I'm highlighting with. I want to just be able to set it to be white or black.
    I am rather averse to using a TextPane, since what I'm writing is designed to edit plain text, and a TextArea has many wheels that I don't want to reinvent, like setTabSize(), for example.
    Clearly, there is code already in place somewhere to draw text a different color for highlighted portions of a TextArea. Is there some way I could perhaps trick only the drawing code into thinking that it has focus? What is the cleanest way to accomplish what I want, i.e. the way that involves rewriting the least amount of functionality?
    Any suggestions/leads would be greatly appreciated.

    Here's a better way to keep the selection visible. All those hard-coded colors are a big no-no, but this is just to demonstrate the technique.
    import java.awt.Color;
    import javax.swing.text.DefaultCaret;
    import javax.swing.text.Highlighter;
    import javax.swing.text.DefaultHighlighter;
    * usage:
    * textComponent.setCaret(new GhostCaret());
    public class GhostCaret extends DefaultCaret
      private static final Highlighter.HighlightPainter unfocusedPainter =
          new DefaultHighlighter.DefaultHighlightPainter(new Color(230, 230, 210));
      private boolean isFocused;
      protected Highlighter.HighlightPainter getSelectionPainter()
        return isFocused ? SimpleHighlighter.defaultPainter : unfocusedPainter;
      public void setSelectionVisible(boolean hasFocus)
        if (hasFocus != isFocused)
          isFocused = hasFocus;
          super.setSelectionVisible(false);
          super.setSelectionVisible(true);
          getComponent().setSelectedTextColor(isFocused ? Color.WHITE : Color.BLACK);
    }

  • I cant use the highlight, underline, or strikethrough function in a specific pdf file. The file isnt locked. I used to highlight texts from that file before the latest update. The problem occurs only with that file. Urgent need. Please help. Thanks!

    i cant use the highlight, underline, or strikethrough function in a specific pdf file. The file isnt locked. I used to highlight texts from that file before the latest update. The problem occurs only with that file. Urgent need. Please help. Thanks!

    Chester31,
    Thank you very much for sharing your file with us!  Now that we are able to reproduce the problem at our end, you may stop sharing the file on Acrobat.com.
    Do you know when this problem (for not being able to add new highlight/strikeout/underline) has started?  Did you update your iOS from 7.x to 8.0 recently?
    We will continue investigating the problem and let you know what we find.
    Thank you again for your help.

  • Highlight text using conditional text

    Hi,
         I need to highlight text using conditional text in InDesign.  I can highlight text using the below code.
    var myDoc = app.activeDocument;
    colorToHighlig = myDoc.conditions.add ({name:"Yellow",indicatorMethod:ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor:UIColors.YELLOW});
    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.changeGrepPreferences.appliedConditions = [colorToHighlig] ;
    app.findGrepPreferences.findWhat = "chapter";
    myDoc.changeGrep();
    But I need to set Indicator to "Show and Print" coz while generation pdf with indicator mode "show", highlights are missing in PDF.  I can retain those highlights with the indicator mode "Show and Print". Dono how to set it..
    If anyone know, pls help me.
    Thanks in advance,
    Sudha K

    Hi,
    it seems, that this one is not a property of the condition, it is a preference:
    myDoc.conditionalTextPreferences.showConditionIndicators = ConditionIndicatorMode.SHOW_AND_PRINT_INDICATORS;

  • Highlight Text using JSObject

    I have a requirement which says to compare 2 PDF files and highlight the differences by adding an image at the text position. I am using JSObject to read the text (word by word) from both PDF's.
    1. Is there any way to find the text position (X/Y co-ordinates)?
    If i get the position of the text, I can use PDF Stamper to attach an image at the location.
    Any ideas??

    > Thats fine. This means I have to change setting for Plug-ins.
    I don't think you quite understand. You're not changing a setting in a plug-in that will make JavaScript return the special characters. What they're saying is that it is not possible in JavaScript, and you will have to create your own plug-in to add this functionality, from scratch, in C/C++ (the only languages available to a plug-in).

  • Is it possible to add highlighted text in an iBooks interactive textbook using VoiceOver?

    Is it possible to add highlighted text in an iBooks interactive textbook using VoiceOver?

    The only way you can add read aloud to an ibook is by using easy epub code editor. (Go to itunes and look it up). This app works on the ipad and is the ONLY app that can generate smil/xml code for read aloud. The only thing is that you cannot use it on anything but a raw epub file. You cannot use it with ibooks author or with any other file. Hope this helps.

  • Can you make a menu for the right-click search so that when I highlight text and search, I can choose which search engine to use?

    If you Highlight text you can right-click on it to pull up a short menu. One option is "Search x search engine for 'highlighted text'" Previously, the search engine selected would be whichever search engine was selected on the search bar, so Google or Amazon.com, etc. Because you can no longer change that selection before you search, the search engine is set to your default. Was an annoyance before, but now it's just a hindrance.

    Strongly recommend Context Search extension which will solve your problem
    - https://addons.mozilla.org/en-US/firefox/addon/context-search/?src=search

  • Highlight Text using X/Y co-ordinates

    I am developing a PDF application using VB.NET. I need to highlight a PDF document using X/Y co-ordinates.
    I get the co-ordinates which define a rectangle like this -
    ?oCoord(0)
    {System.Array}
    (0): 36.0 {Double}
    (1): 799.1719970703125 {Double}
    (2): 39.33599853515625 {Double}
    (3): 799.1719970703125 {Double}
    (4): 36.0 {Double}
    (5): 785.30010986328125 {Double}
    (6): 39.33599853515625 {Double}
    (7): 785.30010986328125 {Double}
    The co-ordinates are fetched using the following method,
    oCoord = JSO.getPageNthWordQuads(Page, Word)
    How do I shade the PDF using the above co-ordinates?

    Thanks Leonard. The highlight option is the one I was looking for.
    When I tested with simple X-Y co-ordinates it works great. But when I give using the co-ordinates what I get from the exact location (i.e., I get 8 values which describe a rectangle), I get the following error,
    "Value does not fall within the expected range."
    Here is the failed code -
    page = pdDoc.AcquirePage(0)
    '' I get pageRect.Y = 842 and pageRect.X = 595
    pageRect = page.GetSize
    popupRect(0) = 36D
    popupRect(1) = 673.171997070312D
    popupRect(2) = 96.69580078125D
    popupRect(3) = 673.171997070312D
    popupRect(4) = 36D
    popupRect(5) = 659.300109863281D
    popupRect(6) = 96.69580078125D
    popupRect(7) = 659.300109863281D
    annot = jso.AddAnnot
    props = annot.getProps
    props.Type = "Highlight"
    annot.setProps(props)
    props = annot.getProps
    props.page = 0
    props.popupRect = popupRect
    props.strokeColor = jso.Color.Yellow
    annot.setProps(props)
    What is that I am missing? Or do I need to do some manipulation with the co-ordinates.
    Here is the code which works fine -
    page = pdDoc.AcquirePage(0)
    '' I get pageRect.Y = 842 and pageRect.X = 595
    pageRect = page.GetSize
    popupRect(0) = 0
    popupRect(1) = pageRect.y
    popupRect(2) = 200
    popupRect(3) = pageRect.y
    annot = jso.AddAnnot
    props = annot.getProps
    props.Type = "Highlight"
    annot.setProps(props)
    props = annot.getProps
    props.page = 0
    props.popupRect = popupRect
    props.strokeColor = jso.Color.Yellow
    annot.setProps(props)

  • Highlighting Text & Auto Text Options

    I've recently migrated from MS Word to Pages, and I'm determined to make this new relationship work. In Word I used its highlighting text (as with a real highlighter--yellow, pink, etc.) feature, as well as its Auto Text feature, in which I had a number of prescribed, hyperlinked comments. (I'm a teacher, and I would auto text things like, "comma error," which would then be linked to a web page about comma errors.
    Can anyone help me discover ways to do both of these in Pages? Also, is there anything for Pages like MS Word's macros?
    Thanks in advance,
    Brad Carpenter

    Welcome to the forums, Brad.
    There is no direct analogue in Pages to Word's highlighting feature. However, you can use the Comments feature to add specific comments to a specific piece of text (with the advantage that the comments can be easily hidden, since you are not changing the characteristics of the actual text). Simply select a bit of text and click the Comment icon in the toolbar, or from the Insert menu select "Comment". The selected text will highlight in document, and a comments box will appear to the left of the page, in which you can type whatever you want. In the comments box you can select whatever text you want and make it a hyperlink, by going to the Hyperlink Inspector. Unfortunately, there is not an easy way to automate the creation of a hyperlink, at least as far as I know.
    There are plenty of third-party applications that will let you store and add snippets of text easily to any Mac document, including Pages. These include TypeIt4Me, Butler, and even Quicksilver, which has a fanatical following and may be more than you need for this kind of task. I'm sure others here might be able to suggest other apps.
    One caution, however: If you intend to be sharing documents with others, they must be using Pages themselves to take advantage of these features. Unless your students are also using Pages, these workarounds won't really help.

  • Highlighting text in  Preview

    Unexpectedly, a strange alteration to how I can highlight text,  when reading a pdf in Preview has occurred. I used to be able to check the highlight icon in the annotations bar and that's about it. Now when I intend to highlight text, the colour extends to being four lines wide, and when I finish - it gets even stranger. Instead of  the text with a straight band of colour - like with a real high-liner pen - odd shapes occur across the text! How to revert to a simple, colour line highlighting the text I feel is important?

    No it has nothing to do with, if the PDF is protected or not. It is not in this case, it is having the PDF open in Preview and holding down the mouse button and dragging and highlighting the information in whatever direction you push your mouse in. Preview seems to only highlight what ever is showing on the screen instead of highlighting from page to page.

  • Highlighting Text In Pages 4 and 5: How To/Best Methods?

    Hello Fellow Macers:
    I need advice on the best way to highlight text in Pages 4 and 5:
    I use and prefer Pages 4.3. Yes, I have Pages 5.2, and I find that using it good for some things (dictating into a document), but not so good for others - highlighting text.
    For example, I read tons of documents and like to make notes, comments and especially highlight text according to a color-code scheme that I have used for years.
    For those who use Word, this process of highlighting text is pretty straight-forward:
    You highlight your text and then simply click your highlight box on the Word toolbar (choose a default color, usually yellow) and you're done. If you need to use another color, just use the pull-down, as seen above. The drawback in Word - no Orange, or sectrum option.
    But let's face it - Word as a program is just too much. As someone who has used every word processing program under the sun, I find Pages excellent. It does what I need.
    However, I find highlighting text in Pages clumsy. Here's what I need to do to highlight text in Pages 4.3:
    Go to your toolbar, and then choose a highlight/background color. It's more labor intensive then Word, above, but you do have the option of more colors.
    Then there's this method, where basically you get to simply use yellow as your color:
    IMHO both are clumsy methods compared to Word, but have become even more so in Pages 5.2....
    Lots of clicks to achieve simple color highlights.
    Am I missing something, or is there a simpler way, in either Pages 4 or Pages 5, to achieve the above results???
    Any suggestions appreciated!

    Dear VikingOSX:
    As Ed MacMahon once said (before your time?) re Pages 5 Character Fill Color: "You are correct, sir!!"
    The gear icon IS where the function that I'm talking about is located. Still, it's annoying.
    Q: Why?
    A: Because from a work-flow perspective as someone who is highlighting it makes no sense. We in the Western world read and write from top to bottom, left to right. Making a mark on a doc should follow the same flow.
    You should not have to keep looking over to the right side of the doc to find your function. Logically it should be at the top (e.g., toolbar), on the left, or perhaps some contextual pop-up option.
    Furthermore, it's more "labor intensive" from this point of view: In Word, once you set the color (which, granted, you may need to change from time to time IF you, like me, use multiple colors as part of your highlighting workflow), you just click the box after highlighting the text - 1 click vs 2, and possibly 3.
    The "richer color" part of my comment was just to note that a flaw, in my view, of Word's basic scheme is that:
    1) It lacks an Orange. And we've all used an Orange highlighter at somepoint, right? Or perhaps, you were like me in High School and threw them instead. But you get the point...and
    2) Having a wider pallatte available as an option - which you do in Apple's scheme - is nice. I use color coding/highlighting to make notes and save time. The colors tell me what's important, what's next important, key terms, etc. Also, for example, if I wanted to outline my highlighting notes, the color scheme (which has a heirarchy based on color, right?) allows me to do this quickly because it's already there.
    As for the Dictation function working on Pages '09/4.3 - again, you are correct, sir! And that's great to know. I had tried to use it before when the new Pages 5 (hitting fn twice on Pages 4.3) but it didn't activate. I tried it after reading your response and Bingo! It's Alive! So thanks for that tip.
    Your keyboard shortcut scheme is an interesting idea, and I may try it as an experiment. My intuition is that it will not work as straight-forwardly as Word's toolbar pull-down will, but I might be wrong. We'll see.
    And yes, I do use Pages '09 (4.3) instead of Pages 5 for exactly this reason (see my discussion)
    Great reply! Thanks!

Maybe you are looking for

  • Purchase Orders Forms

    Hi folks Is there a manner to use the same window call by "Purchase Orders" function PO_POXPOEPO in read-only? Otherwise, is there a function other then PO_POXPOEPO which can call the "Manage Tax: PO" function PO_MANAGE_TAX? Tx

  • Suppress fields based on values

    Hi, I am trying to create an expense report in livecycle where if someone selects from a drop down, based on the result picked, it would show a different field to fill in.  If they don't pick a specific dropdown that has extra fields, then those fiel

  • Account Posting Error

    Hi, On posting my billing document to accounting I am getting an ABAP runtime error "GETWA_NOT_ASSIGNED_RANGE". As I understood it, it was to do with number range assigment for accounting document. But I have already assigned number ranges to my a/c

  • SWT Weird problem

    Hi Everyone: This is a very strange problem I've been having with my particular SWT application. Everything compiles fine, and even funs fine, but when I do run it, none of the GUI components are actually visible on the display. Here's the code: impo

  • Datagrid headerStyles issue

    Hello Folks,       I  need to have my datagrid column header text on top left corner of the column.Is there a way to do it without using renderers.I tried using headerStyles but it just has option to align it to the left,not to the top,left.Please ad