Highlighting text fieldon focus with components

Is there a way to highlight a text field when the focus is in that field. I know on a web page you can do this with JS, but wasn't sure about with AS. I am using components also.

If you just want to highlight one word at a time then you can use:
textComponent.setSelectionStart(...);
textComponent.setSelectionEnd(...);
The above code will use the default selection background/foreground font colours.
Here is an example of a Find/Replace dialog that uses this approach.
http://www.discoverteenergy.com/files/FindReplace.java
If you want to get fancier and use different styles of fonts and colours for different words then you have to use JTextPane which supports StyledDocuments.
The basic approach is to create attribute sets as follows:
MutableAttributeSet comment = new SimpleAttributeSet();
StyleConstants.setForeground(comment, Color.gray);
StyleConstants.setItalic(comment, true);
Document doc = textPane.getDocument();Insert new text into the document with the 'comment' attribute:
doc.insertString( doc.getLength(), "comment text", comment);
Change the attribute of existing text in the document with the 'comment' attribute:
doc.setCharacterAttributes( 0, 3, comment, false );
Here is a simple Java syntax highlighter that uses this approach:
http://www.discoverteenergy.com/files/SyntaxDocument.java
Note, most is the above code is devoted to handling multi-line comments. The main highlighting code is in the 'checkForTokens()' method.

Similar Messages

  • How can I highlight text in iPages with a 'virtual' fluorescent marker

    How can I highlight text in iPages with a virtual fluorescent marker?

    The text highlight option is the little box on the toolbar with the "a" and a diagonal line through it (That is the default transparent highlight option).
    Peter

  • HELP-highlighting text in Word with Snow Leopard...

    I am on my MBP, working within a virtual course dealing w/ Word 2010.... within the coursework, I have to highlight text within the examples I'm working on, in order to move to the next step in the tutorial... I'm having a hard time getting the highlighting to work.... therefore, can't move on...
    Please help........
    thanks

    You can highlight text with the trackpad, see either this article
    http://support.apple.com/kb/HT3211
    or this one
    http://support.apple.com/kb/HT1115
    depending on which model you have.
    Basically you want to click once and hold while moving your finger across the trackpad to highlight the text. It's not easy at first for some people with these trackpads. You might find it helpful to simply purchase a low cost USB mouse for a few dollars, plug it in, and use it for these sorts of things.

  • When highlighting text and searching with Google, even though my default browser is Chrome, it searches with Safari.  How do I change that?

    Using iMac and Maverick OS.  I have Chrome as my default browser.  I find that going to System Preferences/General under default browser, I note that Chrome is chosen as default, yet the browser "above the line" is Safari and Chrome, while checked off is "below the line".  In other words, the top listed browser is Safari which is unchecked with a line underneath, even though all the other browsers are listed below the line and only Chrome has a check mark. 
    When I am on a website and I select words to search in Google, it always searches with Safari instead of Chrome.  How do I change that?

    Thanks for your response.  I think it was my error in that I did not define the problem properly.  Indeed Chrome is my default browser.  And Maverick does not have a "next line" to default to Google.  I can do that in the Chrome settings. 
    My problem is that when I am in another application.....and it is apparently an application native to Maverick....for example Contacts or Calendar, Reminders, Notes, etc., if I highlight a word or phrase, and right click and choose "search with Google", it defaults to Safari.  How do I change that?

  • Can't print highlighted text on pdf's in Preview

    I had printing problems with my office printer Canon IR series. the Canon update UFR II V 2.24 fixed this but brought a new problem.
    I can't print annotated pdf's correctly.
    Any highlighted text is covered with a full colour bar with no text visible under it. It just covers the text.
    Is there a fast way of printing with no annotations or of fixing this problem and just print the highlights correctly?!
    Thanks

    Centrolene wrote:
    Any highlighted text is covered with a full colour bar with no text visible under it. It just covers the text.
    Is there a fast way of printing with no annotations or of fixing this problem and just print the highlights correctly?!
    Just tested this to the iR C3380i using the UFR2 v2.24 and can replicate the symptom. I found that if you change the Graphics Mode from UFR2 to Raster, the text will print. To get to this setting, select to print with the UFR2 driver and change to the Quality menu. Then select Quality Setting button to show the Quality Settings pane. Here you will see the Raster Mode setting. Select and OK the change and now you can print the annotated PDF.
    You will probably note that this workaround was the same solution to the Graphics Mode message that appeared with the previous version of the UFR2 driver with the 10.6.7 update. The v2.24 driver stopped this message from appearing but this latest symptom would suggest there is still something not completely right with this new driver, although I seem to remember there being issues with the older driver on earlier versions of 10.6 and the Graphics Mode setting was the only solution.

  • CS4 no longer allows me to markup highlighted text?

    I am not sure why this code used to work in CS2 and not in CS4.
    I used to be able to tag selected (with text tool) text with a markup tag using the below script. It was simple and worked placing tag markers around the highlighted text. However with CS4 I receive the error… "Adobe InDesign CS4 got an error: Cannot change the element to be associated with this object. Try creating a new element."
    Can anybody PLEASE help me out?
    Thanks in advance,
    Jeff
    tell application "Adobe InDesign CS4"
        activate
        tell document 1
            tell XML element 1
                set t to make XML element with properties {markup tag:"expirationdate"}
            end tell
            tell selection to markup using t
        end tell
    end tell

    Did you use migration with the new OS or did you reinstall the CS4 apps from the original media? If you didn't, then you should uninstall CS4 making sure to check the box to remove preferences, run the Cleaner tool (Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6) and then reinstall CS4. CS4 is totally untested and unsupported on the latest versions of Mac OSes.

  • How do I know if my mouse is bad?  I'm having trouble highlighting text with my mouse, model A1152

    How do I know if my mouse needs to be replaced or if it something else?  I am having increasing trouble highlighting text, it either won't hold the highlighting, or it won't highlight . . . making it impossible to create a link in my emails, to delete text, or copy and paste.
    I have an iMac that is about 4 years old and the mouse that came with it uses a USB port to connect.
    Thanks for any information or suggestions.

    Is it one of those with a little moving/rotating ball on the bottom of it? Have you ever taken that out and cleaned it and the area holding it? It could be dust/dirt in there. I always used a QTip slightly moistened with alcohol.

  • Why can I now highlight text with mouse pointer in Adobe Reader 9

    I just downloaded Adobe Reader X. I think I prefer Reader 9. I don't like being able to click in the document and have a flashing place mark (right terminology?) there. This is now happening in the Reader 9 version too, and I can copy text this way, but I don't want this. I didn't change any preferences. Can anyone help?

    Like I said, I didn't change any of the preferences, so I don't know why this happened. I think it only happened after I opened Adobe Reader X. I see no options in preferences for turning on or off the ability to highlight text with your mouse pointer, and I thought you were not supposed to be able to do this in Adobe Reader 9.

  • How to highlight text with a translucent color

    I have to highlight text from a JTextArea, but the color is too dark... So I'd like to highlight with a translucent color. How can I do it ?
    Here is my code :
    JTextArea jt;
    int beginSelect;
    int endSelect;
    Highlighter hl = jt.getHighlighter();
    DefaultHighlighter.DefaultHighlightPainter hld = new DefaultHighlighter.DefaultHighlightPainter(Color.BLUE);
    try {
    hl.addHighlight(beginSelect, endSelect, hld);
    catch (BadLocationException e) {}
    Thank you.

    import javax.swing.plaf.*;
            Color color = new Color(220, 200, 240, 150);
            ColorUIResource colorResource = new ColorUIResource(color);
            UIManager.put("TextArea.selectionBackground", colorResource);Default for windows is [r=49, g=106, b=197]
    and for metal is [r=204, g=204, b=255].

  • 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.

  • How to highlight text with Adobe Reader XI?

    email [email protected]

    Thanks. The PDF file was made from a web site article and I guess this is the same as scanned as I cannot highlight.  The cursor changes but cannot highlight what I want.
    I was able to add text and I did this in Red and will ask the VA to read under the sections marked in Red.
    Thanks,
    Vernon Pobanz
          From: ~graffiti <[email protected]>
    To: vernon pobang <[email protected]>
    Sent: Tuesday, October 7, 2014 11:57 AM
    Subject:  How to highlight text with Adobe Reader XI?
    How to highlight text with Adobe Reader XI?
    created by ~graffiti in Adobe Reader - View the full discussionUse the highlight tool under Comment>Annotations. This will only work if the pdf isn't a scanned image. If that is the case, there is no text to highlight. Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at https://forums.adobe.com/message/6800192#6800192 Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page:  To unsubscribe from this thread, please visit the message page at . In the Actions box on the right, click the Stop Email Notifications link.  Start a new discussion in Adobe Reader by email or at Adobe Community For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • Find an highlight text with Excel vba an Acobat XI Pro

    Hello,
    i want to write a VBA Script to search for and highlight text.
    Until now my Script open the PDF and search for text. But how can i highlight it ?
    Thank you.
    Axel
    My Code :
    Sub OpenPDFPageView()
        Dim PDFApp As AcroApp
        Dim PDFDoc As AcroAVDoc
        Dim PDFPageView As AcroAvPageView
        Dim PDFPath As String
        Dim DisplayPage As Integer
        PDFPath = "C:\Users\info_000\Desktop\test.pdf"
        'Set the page you want to be displayed
        DisplayPage = 1
        'Initialize Acrobat by creating App object
        Set PDFApp = CreateObject("AcroExch.App")
        'Set AVDoc object
        Set PDFDoc = CreateObject("AcroExch.AVDoc")
        'Open the PDF
        If PDFDoc.Open(PDFPath, "") = True Then
            PDFDoc.BringToFront
            'Maximize the document
            Call PDFDoc.Maximize(True)
            Set PDFPageView = PDFDoc.GetAVPageView()
            'Go to the desired page
            'The first page is 0
            Call PDFPageView.GoTo(DisplayPage - 1)
            'Set the page view of the pdf
            Call PDFPageView.ZoomTo(2, 50)
        End If
        If PDFDoc.FindText("blabla", 1, 1, 1) = True Then
            Debug.Print "gefunden"
            call pdfdoc.
        Else
            Debug.Print "nicht gefunden"
        End If
        Set PDFApp = Nothing
        Set PDFDoc = Nothing
        On Error Resume Next
        'Show the adobe application
        PDFApp.Show
        'Set the focus to adobe acrobat pro
        AppActivate "Adobe Acrobat Pro"
    End Sub

    With Acrobat Javascript you can search for words, retrieve the position of the found words, and add annotations at this positions.

  • Vim keeps freezing and I cannot highlight text with my mouse

    title says it all.  Vim will freeze on me randomly.  I was having X issues earlier but stopped using the nvidia driver and that seemed to fix that, but now Vim freezes.  I'll be in Insert mode and it simply will not accept any of my keystrokes or attempts to esc to command mode.
    Eventually it'll unfreeze and then process all the keys I pressed while it was frozen (about 1-2 minutes later).
    The only thing going on in my .vimrc is a color scheme.  This happens in urxvt, in an ssh shell, and in screen.   
    And for some reason I can't used my mouse to highlight text in vim either in all the shells previously listed.

    Try resetting the SMC and PRAM.
    Barry

  • Can I email iBooks notes with highlighted text?

    I've been reading a book in iBooks and highlighting and taking notes. When I view my notes on my device it shows the highlighted text, but when I send the notes to my Evernote account (or any email account) I am not able to see the highlights I made. Is this a copyright issue? Or am I doing something wrong? Thanks for the help.

    Unless your Lotus Notes email server allows POP or IMAP access into it from an email client, then no, there is no way.

  • Highlighting text in a table cell

    Im trying to get text in a table have it background shaded a different colour to the rest of the table cell but it doesnt work. No exceptions are thrown does anyone have any idea.
    public Component getTableCellRendererComponent(JTable table,
            Object value,
            boolean isSelected,
            boolean hasFocus,
            int row,
            int column)
            setFont(table.getFont());     
            this.setText(value));
            this.selectAll();
            this.setSelectionColor(new Color(0,0,255,100);
            return this;
        }

    The answer is similar to what someone else asked recently for highlighting text in a JFormattedTextField cell.
    class MyFocusListener extends FocusAdapter
    public void focusGained(FocusEvent e)
    SwingUtilities.invokeLater(new Runnable()
    public void run()
    selectAll();
    Put that in your cell editor or its base class. You can change the color or whatever you want. I think the problem is a timing thing where normal focus processing is interrupting your changes. So give the focus processing time to run with this Runnable triggering your processing to occur on the Awt thread (as is proper) after the system is doing whatever it wants to do. Let us know if it works for you.

Maybe you are looking for

  • Z-Button - How to call a Action Profile to Open a PDF-Doc. within an Event?

    Hi Experts, we have created a Z-Button that afterwards creates an event. In the coding for the event an Action Profile should be called and a PDF-Document should be opened. We have copied the coding from the standard button 'Print Preview' which is c

  • Network set up using airport extreme, time capsule and airport express

    I have searched for relevant answers but can only find different bits here and there. My set up is as follows: I have a Linksys wireless router running a stable wireless network for the other computer users in the house and wish to create an extended

  • How do I re-install my iTunes Playlist

    I updated my iTunes 10.7 to the new and improved iTunes 11, and I hate it. So I deleted it from my laptop and re-installed iTunes 10.7. However, iTunes 10.7 will not recogize my Playlist, or the back-up Playlist. Is there a way to re-install my iTune

  • Applet display problem in 1.4.2_10

    I recently upgraded JRE from 1.4.2_07 to 1.4.2_10 and my applet page refresh got screwed up. Sometimes when the page with the applet is refreshed, the applet is not displayed. It is loaded for sure but not displayed. If we switch back to some window

  • Have a look at my RFC call, it doesn't return anything

    Hi all, In my project, I create a RFC Model named 'SCO' which will call bapi function 'BAPI_SALESORDER_CREATEFROMDAT1', if successfully a SALEDOCUMENT should return. below is the code in my custom controller   public void wdDoInit()     //@@begin wdD