Font Color problem with JEditorPane

am designing an application whch will change the forecolor the keywords as the user type. like many java ide. but i am not able to do this.
this is what i am doing. start and end refers to the start and end position of the keyword.
if its a keyword i have to make it red.
if not make it black.
How to do this...
if(isKeyWord(editor.getText(start,end-start))) {
          System.out.println("found : " + start + ":" + end);
          editor.setSelectionStart(start);
          editor.setSelectionEnd(end);
          editor.setSelectedTextColor(Color.RED);
     }else {
          System.out.println("not found : " + start + ":" + end);
          editor.setSelectionStart(start);
          editor.setSelectionEnd(end);
          editor.setSelectedTextColor(Color.RED);
so please help me...
thank u

Asked and answered two days ago in this posting:
http://forum.java.sun.com/thread.jspa?threadID=775635

Similar Messages

  • Font color issue with inserted HTML content in JTextPane (HTMLEditor)

    Hi everyone,
    I have a very serious issue with the HTMLEditor I'm developping. This editor is a little bit special since it is intended to edit blocks of HTML content that are loaded when the editor is initialized.
    You can in fact decide to keep this loaded HTML content or start a new HTML document from scratch. Alright, now my issue is the following :
    When text is loaded, it's properly rendered. I have a functionality which let's you see the HTML code from the HTML document used in the editor, so I can check and see if code is correct, and yes, it's correct.
    The problem is that when I try to change the color attribute of some text on my loaded content, nothing happens ! I don't know what's the matter with this bug, I only have it with the color attribute, with every other attribute everything's fine (font, size, etc.)
    The funny thing is that, after I change another attribute for loaded content, like font family, then changing color attribute funcionnality starts to work again !
    I've also noticed that I don't have any of these problems when I start my HTMLDocument from scratch (when I create a new HTML document and start typing text).
    Another weird thing, is that I have a feed-back feature in my editor which reflects attributes for text over which the caret is positionned. For example, if you put caret over red text, the color combo box displays a red value, you know, just like in MS Word. Well, with my loaded content if I have a red text color and I decide to put it in green, the color combo box displays the green value when I click over text for which I have changed color, but in my JTextPane it's still red !! And when I try to see the HTML code generated nothing has changed, everything is still red !
    There is something really strange here, this means that when I get the attributes of the loaded text from the HTMLDocument, color appears to be green, but when it gets rendered in the JTextPane it's still red and when it gets anlyzed to produce the corresponding HTML code, these changed attributes are not taken into account.
    But the most weird thing above all, is that I don't have this bug everytime, sometimes I start my HTML editor applet and it works fine, and some other times this color issue is bakc there. Is this a known bug for Swing API or not ?
    =============
    This is more or less my technique :
    //I declare a global reference to my HTMLDocument
    HTMLDocument _docHTMLDoc;
    //Create a JTextPane
    JTextPane _tpaEditor = new JTextPane( );
    //Set type content to automatically select HTMLEditorKit
    _tpaEditor.setContentType("text/html");
    //Get a referene to its HTMLEditorKit
    HTMLEditorKit _kitHTMLEditor = (HTMLEditorKit) _tpaEditor.getEditorKit( );
    //I then have a function to create new documents
    void newDocument(){
      _docHTMLDoc = (HTMLDocument) _kitHTMLEditor.createDefaultDocument();
      _tpaEditor.setDocument(_docHTMLDoc);
       //I do other stuff wich are not important to be shown here
    //I then have another function to load content
    void loadContent(){
       //I get content from a HashMap I initialized when I started my applet
       String strContent = (String)_mapInitParameters.get("html_content");
       //I set content for my editor
       _tpaEditor.setText(strContent);
    //Notice.. I have tried many other ways to load this text : via HTMLEditorKit and its insertHTML method, I
    //have also tried to store this content in some reader and make HTMLEditorKit read it... and nothing,
    // I always get the bug
    //To change color it goes like this :
    JComboBox _cboColor = new JComboBox();
    //I correctly initialize this combo with colors
    //then I do something like this
    ActionListener _lst = new ActionListener(){
       public void actionPeformed(ActionEvent e){
          Color colSel = (Color) _cboColor.getSelectedItem();
          MutableAttributeSet mas = new SimpleAttributeSet();
          StyleConstants.setForeground(mas,colSel);
          setAttributeSet(mas);
    _cboColor.addActionListener(_lst);
    //Set Attributes goes something like this
    private void setAttributeSet(javax.swing.text.AttributeSet atrAttributeSet) {       
            //Get current 'End' and 'Start' positions
            int intCurrPosStart = _tpaEditor.getSelectionStart();
            int intCurrPosEnd = _tpaEditor.getSelectionEnd();
            if(intCurrPosStart != intCurrPosEnd){
                //Apply attributes to selection
                _docHTMLDoc.setCharacterAttributes(intCurrPosStart,intCurrPosEnd - intCurrPosStart,atrAttributeSet,false);
            else{
                //No selection : apply attributes to further typed text
                MutableAttributeSet atrInputAttributes = _kitHTMLEditor.getInputAttributes();
                atrInputAttributes.addAttributes(atrAttributeSet);

    hi, friend!
    try this:
    void setAttributeToText(JTextPane pane, int start, int end, Color color) {
    MutableAttributeSet new_att = new SimpleAttributeSet();
    StyleConstants.setForeground(new_att,color);
    HTMLDocument doc=(HTMLDocument)pane.getDocument();
    doc.setCharacterAttributes(start,end,new_att,false);
    It works fine in my Application, hope will work in yours, too.
    good luck.

  • Font color problems in one forum

    I'm in a classical music forum--for at least 3 years I could post and reply to messages with my blackberry with a minimum of difficulty.  However in the last month when I go to post my reply before I reach the submit option on the screen the font color boxes the forum offers now appear and there are many color choices.  It takes a long time to scroll down to where I have to be to hit submit?  Is there any option on the blackberry to avoid having to do this?   Can I eliminate having to see these big colored boxes every time I post or reply?  Any help would be appreciated.  Regards, Len

    I have found a serious problem in my 17inch imac, the colors in the upper side of the screen looks darker that the bottom, if you make a rectangle in a dark red color in illustrator or photoshop it looks like a gradient, the color is not solid, My imac is just 2moths old, what can i do, I send it to my local apple service provider ( guadalajara mexico), and they change the display for a new one, and te failures is still there, they want now to change the logical board....wath can a I do if they do not can fix it?... excuse my inglish by the way

  • Color problem with ProPhoto RGB color space

    Hi, everyone,
    I have wery special problem I think. I use MacBook pro 15" with retina display, adobe Photoshop CC and when I export RAW (from Nikon D7000) from Lightroom 5 to Photoshop with settings: 16 bit TIF, color space: ProPhoto RGB I have a problem with displaying the correct colors. As you can see in this picture:
    My problem are some "green" artefacts in absolutely black and white picture. I tried myself to solve this problem and found the following facts: when I convert picture into Adobe RGB or sRGB color space is everything OK - without green artefacts.
    But here is one important fact: I have calibrated monitor by datacolor spyder4elite and problem with ProPhoto RGB incorrect color displaying is only when the color calibration configuration is loaded. When I change my display calibration to standard apple color LCD profile than is everything OK.
    But using uncalibrated monitor and also Adobe RGB color space are no right solutions for me.
    My question is why I have problem with displaying ProPhoto RGB color space in photoshop under calibrated monitor profile and can anybody help me please?
    Thanks for answers.

    That's a classic example of the basic problem with 16 bit color. There is no solution that I know of.

  • Lion Font Book problem with Adobe FontFolio 11

    I have a fresh install of Lion. My problem is with FontFolio 11. It installs well, finds duplicates etc. The problem happens only after i deactivate all of the fontfolio fonts. After they have all be deactivated, if I click on any other font collection, fontd jumps up to 99% CPU usage and Font Book not responding. After 5 minutes of this Font Book's Real Mem usage slowly starts to increase, sometimes up to 3 gigs. Eventually, I am able to click through collection with no delay, however, after a system restart or just a Font Book restart, the process starts over and i have to wait.
    I have tried:
    Clearing every font cache file I can think of.
    Using Font Finagler to clear font caches.
    Restarting in safe mode.
    Creating a new user.
    Nothing has made this problem go away.
    So, what exactly is happening? Why is Font Book fast and responsive with my 427 fontfolio fonts active, but when i deactivate them it slows to a crawl and goes through the same CPU/memory cycle every time? I have research and experimented for a solid week. I can't waste any more time on this. I'm this close to giving LION and Font Book the big thumbs down and buying something that actually works.
    I never had a problem with snow leopard using Font Book and the same version font folio.

    Same here. My thread: https://discussions.apple.com/message/15995212#15995212
    I've had no replies. Have you looked at Activity Monitor while this is happening? check it out. I think i'm just going to go back to Leopard, don't know what else to do. Do you have an SSD in there?

  • Fonts display problem with Entourage

    Hello,
    I am a new Mac user, having just migrated from Vista to iMac. I love my mac but I am experiencing a problem with how Entourage is displaying some of my emails.
    They display as weird caracters and symbols, but not all of my email does this, just some. The individual characters display with "V' over some of them, and the sizes are all over the map and it is hard to read. However, if I copy and paste into another program, it displays normally. I'm stumped! I hope a more experience Mac user can help me with this.
    Cheers!
    ~Pauline

    They display as weird caracters and symbols, but not all of my email does this, just some.
    It's probably caused by a bad font. If you have Times Phonetic, get rid of it. Send me a screenshot if you want (tom at bluesky dot org).

  • Serious color problems with Lightroom

    Hello,
    I purchased lightroom this week and I am having a serious problem importing images. I am using a new Macbook Pro with OS Snow leopard. My camera is a Canon 1ds Mark2.
    When I import files half of them have this awful deep orange cast over them.
    If you look at the thumbnails some of the frames are normal and then the next few turn orange, all shot within seconds of each other in the same place, no WB change on the camera or anything. What is this, a bug in Lightroom? I dont experience this problem with Photomechanic or Photoshop.

    It doesn't sound like you know what actually caused the problem. What happens if you 'delete' (i.e. remove from LR only) some of the previous "orange" pictures and try to reimport them into LR?
    I understand that you are new to Lightroom – Welcome aboard! Your first step after learning the basic controls in LR is to adjust your 'Camera Default Settings' in the Develop module to better suit your workflow. I suspect you are using your camera with 'Auto White Balance' (AWB) set, which is inappropriate for RAW file format. Reason: If your LR Develop module white balance control is set to anything other than 'As Shot,' then pictures shot under different color temperature lighting will take on different color casts (i.e. orange, blue). The controls you have in LR (White Balance eye dropper) can help you to better determine the white balance settings for a particular shoot, and easily apply them uniformally across multiple pictures. This will provide better results than using AWB on any camera!
    I use a ColorChecker Passport to create custom camera profile and white balance develop presets for 'Daylight,' 'Cloudy,' Tungsten,' etc. for each of my camera bodies. Therefore I never use 'As Shot' white balance setting, and never have this kind of problem. My default camera setting uses the ColorChecker custom 'Daylight' preset, which I can change to a different preset for any photo session that was not shot under normal daylight conditions. If you want good color control of your images, you should not rely on the 'Auto White Balance' setting on your camera (especially for JPEGs!). You don't need a ColorChecker to adjust your camera body's color temperature in LR, but it helps and also creates a full custom camera profile! I own three Canon camera bodies and they all produce slightly inacurrate white balance using LR's 'Daylight' white balance setting with high-noon sunny daylight pictures. I suggest you determine and create your own custom white balance settings in LR for daylight and then change your camera default to these settings. You can also create custom develop presets for Cloudy, Tungsten. etc., which can be applied to specific shooting sessions as a better "starting point" for white balance.
    Do a little research on using Lightroom's White Balance Eyedropper tool – Here's one link:
    http://help.adobe.com/en_US/Lightroom/3.0/Using/WS947672F1-AAB2-43de-9011-BDDECA05EC19.htm l

  • Color problems with previews

    during my 30 day trial of LR, LR developed a problem with the color displayed of any files(jpeg or raw) that I imported into the program. the reds and oranges seemed to be way over saturated .if I exported the unedited file to any other location the photo would look fine. if I edited the file to look right when I exported it it looked way off. I was loving the way the program worked for the first week but it became unuseable after that. Im using a canon 40d and the problem occures when importing directly from the camera or fron any folders on my pc running xp .... any thoughts???

    >Odd how it could look fine with windows and others but really off with LR.
    None of the others typically color manage, so they don't use the profile. Also, a large number of the icc profiles that are shipped with display drivers for windows ar corrupt out of the box (really strange but true) so you're usually better off just deleting them. That said, if you want good color you basically have to actually calibrate. Using sRGB is a very bad alternative. You need to calibrate using real calibration hardware for good color and use color managed apps wherever you can (Lightroom, Photoshop, Safari, Firefox with the secret setting enabled, but NOT internet explorer or windows picture viewer. They never show you the actual color.

  • Bizarre color problem with macmini

    I just bought a mac mini intel. And have it hooked up to a JVC hdtv with DVI-DVI.
    In some windows. Everything is blue and yellow. No reds show up. But it's completely erratic.
    For instance: On the dock, all logos look fine. When I launch front row (just the opening screen) everything is blue and yellow.
    Most photo's go blue and yellow in iphoto. but display fine in front row sometimes.
    The open, close, minimize logos are always the correct colors. Even if the info within the window is not.
    This is not a monitor problem. Or a cable hookup issue. It's either software/color profile. Or hardware.
    Do anyone know how to fix this? Apple is clueless.

    That's a classic example of the basic problem with 16 bit color. There is no solution that I know of.

  • Font color problem upgrading from 1.3.1 to 1.4.2_02

    I have noticed when we upgraded from 1.3.1 to 1.4.2_02 that JLabel font color is now black - it used to be blue. Does anyone know how to make the font color of JLabels revert back to the original blue without specifically calling setForeground() on each label?

    Sun has changed in the class MetalTheme the method
    JDK 1.3.1: public ColorUIResource getSystemTextColor() { return getPrimary1(); } into
    JDK 1.4.2: public ColorUIResource getSystemTextColor() { return getBlack(); }
    Just insert the following lines at the beginning of your main-method:
    MetalLookAndFeel.setCurrentTheme( new DefaultMetalTheme()
    { public ColorUIResource getSystemTextColor() { return getPrimary1(); }
    try{ UIManager.setLookAndFeel( "Metal" ); }
    catch( Exception e ){ e.printStackTrace(); }
    Now you have the old colors

  • Type(font) color problem?

    every time i type sometnig new font color changes to black
    before i start typing i chose some color for example red and when select type tool(t) and click where i want to type color chage to black?
    why?

    always state what version you are using changing the current fill and/or using maintain appearance does not apply to the character color text it defaults to black because that is the color of the default character style either use your colored text to redefine the default character style or create a new character style based on the type settings you want
    See how annoying it is to have to read "clever and chik" web-speak?
    JET

  • Problem with JEditorPane p lost when press ENTER

    OK, so here goes my problem.
    I have in my application a JEditorPane which formats text with bold italic and so on.
    The user can save this into a text file.
    So far so good, but the new lines are lost, no <p> tag is inserted, and no ALIGN either. All other tags - <b> <i> work fine.
    If I insert <p> tags into the text file and then open it in my application, they remain there fine.
    Any idea on this one?
    P.S. pls include some code samples, I'm not advanced ;)

    here is some code what i have used in my report program , i will still like to remind that its an Logical database program (PNP) for ABAP-HR , right now i tried the code mentioned above but not getting any result.
    TABLES: pernr,sscrfields,pa0001.
    *& Declaring Type-pools
    TYPE-POOLS : slis.
    *& Declaring Infotypes
    INFOTYPES: 0000,          " Action
                         0001.          " Org. Assignment
    *& Selection Screen
    SELECTION-SCREEN BEGIN OF BLOCK n1 WITH FRAME TITLE t1.
    PARAMETER : p_despat TYPE zhr_transfer-despt OBLIGATORY,              " Despatch Number
                r_pernr  TYPE pa0001-pernr OBLIGATORY,                                    " Reporting to
                re_pernr TYPE pa0001-pernr OBLIGATORY,                                   " Relieving Authority
                a_pernr  TYPE pa0001-pernr OBLIGATORY MODIF ID one.             " Authorize Person
    SELECTION-SCREEN END OF BLOCK n1.
    INITIALIZATION.
      t1 = 'Transfer Records'.
      LOOP AT SCREEN.
        IF screen-name = 'PNPPERNR-LOW'.                                  " Personnel Number (Mandatory)
          screen-required = 1.
            MODIFY SCREEN.
        ENDIF.
      ENDLOOP.
    AT SELECTION-SCREEN OUTPUT.
      IF a_pernr IS INITIAL.
        a_pernr = pa0001-ename.
      ENDIF.
    END-OF-SELECTION.

  • Web Kit Font Display Problem with "BEBAS NEUE"?

    Since today font "Bebas Neue" is not displayed correctly.
    Online connection is ok. Font is displayed only when published.
    Thanks for help.

    I tried that temporary solution but, in my design, I use boxes and triggers etc. and since the "replacement" font for the Bebas Neue is so different from the original, it somehow effected my design (white rectangles under the boxes).
    The first image: Font uploaded manually, hence rendered as image, and the contour is not good. (Look at the letter A) (partial screenshot from browser)
    The second image: The font is Bebas Web Font(!) in Adobe Muse (partial screenshot from adobe muse)
    The third image: Font left as is; Bebas Web Font published as it is in the second image, displayed correctly as font BUT there is a white rectangle under the box. (partial screenshot from browser)
    By the way I am using Macbook Pro, Mac OS X 10.9.2, Adobe Creative Cloud Single Edition (Muse CC v7.2 Build 232). Yesterday I worked with the same design without any problems. Nothing updated since then.

  • Color problems with miniport to HDMI?

    Hi, and thanks for reading.
    I'm not very familiar with Macs, so I'm hoping the problem I'm having is straightforward.  My wife has a MacBook Pro with v. 10.6.7 OSX and I just got a Kanex miniport to HDMI cable to connect it to our Westinghouse 720p LCD TV (SK-26H240S).  The plug and play connection worked fine, and I can use the display in either clone or extended desktop mode, but the color is all wrong.  I've tried changing all the settings on the TV and I've tried calibrating the color profile in system preferences, but nothing seems to work.  I can get all sorts of different wrong colors, but not the right color.  It seems like the data being transmitted for either white or black is wrong: a gray screen on the laptop shows up as blue on the display.
    I have seen a number of other issues posted here about using these adaptors, but as far as I can tell, they are intermittent problems, whereas mine is always having the same problem.  Any ideas out there?
    Many thanks
    <edit>I just noticed the laptop makes a humming noise ( ! ) when the cable is plugged in.  Probably a red herring, but thought I'd mention it as it seemed kind of weird.

    laura99 wrote:
    I seem to have the same problem but mine will display my background screensaver. what should i do. it won't show anything else? Thanks ahead of time.
    You have a different issue, which is probably not actually a problem. When you connect the TV, the Mac probably thinks of it as an external monitor to add space to your desktop. If so, it won't show what's on the laptop monitor because that's a separate area...but you can drag windows over there to the new monitor. What you are seeing is not any screen saver, but your desktop background, since you've added to your desktop.
    If you want to see the same thing on both monitors, turn on mirroring with the displays icon in the menu bar. To customize how the Mac uses your external TV/monitor, use the Displays preference. There you can switch mirroring on or off, and also tell the Mac how the monitors are arranged.
    If you turn on mirroring, the screen might not exactly fill the TV since it is probably a different resolution than the laptop screen, but under mirroring you can use only one resolution.

  • Font color issue with animated text in Captivate 5

    When I prepare a new animated text and open the property and then click the square to choose a color , I only get a  little part of the color panel (when I click the color box) and I have  no possibilities to enter the color code either:
    I'm working with a Windows XP, 64 bits desktop and I have Captivate 5 version 5.0.1.624.
    Any ideas to solve this issue would be appreciated as it is becoming urgent for me.

    @Lieve: You're on the French version of Captivate 5 aren't you?
    Can you provide a screenshot of what the Animated Text font colour dialog looks like on your PC and upload it here?
    This is what that box looks like for me:
    It seems that on this user's PC the colour picker isn't able to float on top of the dialog as it should.
    I encouraged Valerie to post her issue on this forum in the hope that one of the Captivate developer technicians would chime in with a possible solution.  I think this one has got to be some kind of bug due to a language version of Cp.

Maybe you are looking for