Any ideas on this one??  textpane weird thing

I need to search through the document in a jTextPane and color certain words...I had it working but it skipped a character on every new line. I searched and found this, http://forum.java.sun.com/thread.jsp?forum=31&thread=42144 but it does not help with a solution. Can someone please help.
          StringTokenizer sT = new StringTokenizer( textArea.getText() );
               int numberOfTokens = sT.countTokens();
     int startpos = 0;
          for( int j = 0; j < numberOfTokens; j++ )
                    //System.out.println("After For Loop");
                    String token = sT.nextToken();
                    if( token.equalsIgnoreCase( "test" ) )
                         //System.out.println("in if loop");
                         //System.out.println(token);
                         textArea.select( textArea.getText().indexOf( token,startpos ), ( textArea.getText().indexOf( token,startpos ) + token.length() ) );
int start = textArea.getSelectionStart();//textArea.getText().indexOf("test",startpos);
int end = textArea.getSelectionEnd();//start + 3;//
startpos = start+1;
System.out.println("after start,end "+start+" "+end);
if (start != end)
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setForeground(attr, Color.red);
doc.setCharacterAttributes(start, end-start, attr, true);
textArea.requestFocus();

Here's an idea that should work...
int start = textArea.getSelectionStart();//textArea.getText().indexOf("test",startpos);
int end = textArea.getSelectionEnd();//start + 3;//
// CHANGE
// right here, check if you've crossed a newline
// if you have, update startpos, and subtract 1 character
while (int x = textArea.getText().substring(startpos,start).indexOf('\n')!=-1) // there is a newline character
startpos = x + 1;
start -= 1;
startpos = start+1;
that should fix it

Similar Messages

  • Missing from the "Missing Manual"; any ideas on this one?

    Greetings Wizards, Gurus, Freakazoids, and anyone else willing to share their wisdom,
    I recently upgraded to iMovieHD (5.0.2) and have come across a few anomolies; some harmless and some downright debilitating (and stupid, I might add), for instance:
    What is this @%#$ "Updating Files - This could take awhile" message?! It interrupts every process. Sometimes it's just during an edit, but earlier today it interrupted a capture and blew the whole clip (it was a 10 minute clip for time lapse). I had to go back and start over.
    Fortunately, it didn't take "awhile", but in previous sessions it really did. Sometimes 5 minutes or more. What is this process and how can one avoid/work around it?
    Perhaps related, perhaps not, but I was working with large clips today (for a time-lapse project; many 5 - 10 minutes long) and found that it was nearly impossible to scrub through these clips without invoking the Spinning Beachball Of Death. Now I'm guessing that it may have something to do with a really long clip being scrubbed too fast, but here's the issue: I have a 2.5GHz DP G5 and it can't seem to handle the same thing I was able to do with my trusty old 450MHz G4 running iMovie 3.03. I've never had problems like this. In addition, it doesn't seem to depend on length; I can scrub 10 minute clips fine and then it'll hang up on a 6 minute clip. Next I'll try a 12 minute clip - no luck. However, it always has problems with the same clips.
    And they call this an upgrade?!......don't even get me started on the whole "non-destructive editing" thing....
    Any ideas?
    In the immortal words of James Brown,
    Please, Please, Please, Please,..........help a brother out.
    Thanks,
    Chris
    PPC G4 450, 768 MB RAM + G5 2.5DP, 512 MB RAM   Mac OS X (10.3.9)  

    Wow. That's brutal. I think I would have scratched my eyes out by then.....
    We do our own letterboxing, so we shoot 4:3 with tape over the monitor (or the camera's LCD - really) and frame for that. (we call it "ghettoboxing" - I suppose we'll have to stop calling it that at some point.)
    Anyway, it's easier to deal with in post because we never have to worry about squeezing or unsqueezing, etc. It always looks right, and well, there's a certain amount of caché when one walks around with a $4000 camera with tape stuck all over the monitor....
    Even classier, I have a china marker in the edit suite so I can draw the lines on the monitor and line up the letterboxing. Nothing but the best for our clients....."Wait, we have clients?! Where?!"
    If you've got a lot of clips it can be a drag, but I usually select a screen-length's worth in the timeline and render the letterbox on all at the same time, scrub forward and do it again to the next batch. The settings usually stay the same from the last time you used the effect, so it works out.
    The more I think about it, the more I think it has something to do with the drop-frame time code. I don't think the Quicktime engine is able to deal with it effectively, especially if there are dropouts on the tape. Which in this case, ther seemed to be on a couple of clips.
    Not sure why 16x9 would cause an issue, unless it's somesort of rendering or conversion issue. When you view your clips back onscreen, are they squeezed, or does IM accomodate the format and stretch the preview monitor?
    - Chris
    PPC G4 450, 512 MB RAM + G5 2.5DP, 512 MB RAM   Mac OS X (10.3.7)  

  • Error message "the ipad 'ipads name' cannot be synched. You do not have enough access priviledges for this operation" Any one got any ideas on this one?

    This error message only come up on my ipad since the shift to ios7. It doesn't happen on my iphone 5, just my ipad. It's a 3rd generation. If I uncheck sync photo's it works fine? If check photo's it comes up with the error message. Its a real pain as I want to have access to my photo stream. Any ideas?

    iPhone - not enough access privileges: Apple Support Communities
    Also,
    Have you looked at the previous discussions listed on the right side of this page under the heading "More Like This"?

  • HT2577 This is not the first time I have woke up to finding my Mac in the sleep mod, and the airport on and connected. Any ideas about this one?

    Is it possible to access and not leave a calling card of access in the system? I had a service result that went bad, and required another service result that reinstalled the Mt.Lion. Bad being that they did not install as the paper work stated. OSX 10.8.5 questions my ability to protect access. Any thoughts on technical support being to technical with personal information?

    Go here:
    http://www.apple.com/support/itunes/contact/
    and follow the instructions to report the issue to the iTunes Store.
    Regards.

  • My Mac won't read cyrillic in certain files and displays instead weird characters like this: "–í–µ-Ç–µ-Ä –ø-Ä–æ–¥–∏-Ä–∞–µ-Ç –¥–æ –∫–æ-Å-Ç–µ–π." Any ideas why this might be or how I can solve it?

    Yesterday I extracted the subtitles of an MKV file to try and print them. Unfortunately, when I open the .srt file with any text processor, it displays weird characters like the ones included in the title:
    "–û–±—ã–≤–∞—Ç–µ–ª–∏ –ø–µ—á–∞–ª—å–Ω—ã.
    –í–µ—Ç–µ—Ä –ø—Ä–æ–¥–∏—Ä–∞–µ—Ç –¥–æ –∫–æ—Å—Ç–µ–π."
    I thought this had to do with it being an .srt file, but just now I encountered the same problem with an Excel file.
    Any ideas why this might be or suggestions as to how to solve it?
    Thanks in advance,
    Mario

    It looks like an encoding problem.  You should try opening the file in a text editor where you can choose one of the various possible cyrillic encodings (utf-8, koi8-r, iso-8859-5, win-1251, MacCyrillic)

  • I use MAIL exclusively. I have a number of Mailboxes set up. My messages will not load on one particular Mailbox on my MacBookair, but do load in that Mailbox on my IOS devices. Any idea why this is happening?

    I use MAIL exclusively. I have a number of Mailboxes set up. My messages will not load on one particular Mailbox on my MacBookair, but do load in that Mailbox on my IOS devices. Any idea why this is happening?

    No idea at all, it might help if you gave more information, what type of mail, who provides it, any error messages etc.

  • Some photos from one day are showing up on my photo stream, and others from that same day are not. Any idea why this might be?

    Took a bunch of photos on vacation one day, and it seems like the first batch from one day are not showing up, but then all of a sudden, the ones from the second half of the day are there. They are not showing up on the photostream on my iPhone on which I took the photos, or on my iPad or in iPhoto on my computer. Any idea why this could be happening? All the other photos I took all week showed up on my Photostream.
    Is there anyway to force these photos into the photostream?
    Thanks! Any help would be appreciated!

    photo stream uploads photos from your photo app when it is connected to wifi and the photo app has been closed correctly.  That may be why your seeing photos pop up on different dates
    http://support.apple.com/kb/HT4486

  • My wifi goes down at least once a day and I have to unplug the time capsule and reboot it and then it works fine.  Any idea why this is happening/what I can do to fix it?

    My wifi goes down at least once a day and I have to unplug the time capsule and reboot it and then it works fine.  Any idea why this is happening/what I can do to fix it?

    I was having this problem while still using Mavericks -- it started after a Mavericks update last spring.  During the initial Yosemite beta runs over the summer, it seemed to be fixed, but after the official launch in October, I had all sorts of problems keeping connected.  Its gotten a little better, but still happens to at least one of my devices every day.  Weird that we still cannot figure out why the connection keeps dropping on some devices, but not others, and then the next day, one of the devices that didn't disconnect the previous day will disconnect, but the ones that did disconnect, stay connected.  It's just sloppy, poorly written software for technology that isn't working the way it should.  If you turn off Continuity and Handoff on all your devices, you will probably see that everything stays connected.  With those turned off on all devices, TC stayed connected to everything for over a month.  The day I turned Continuity back on, all the problems started again.  It had something to do with the bluetooth version being used, the wifi routine, and Apple's AirPlay technology not quite getting along with each other.

  • I have attempted to update a few apps and the install has frozen on 'waiting' not allowing me to either access the app or delete it, any idea why this has happened and how do I get around it?

    I have attempted to update a few apps and the install has frozen on 'waiting' not allowing me to either access the app or delete it, any idea why this has happened and how do I get around it?

    See if either of these things works for you. In the future ... Only update one app at a time. Forget that the Update All button even exists. It causes more problems than it does good - IMO.
    Make sure that you do not have a stalled download in iTunes - a song or podcast .... if you have a download in there that did not finish, complete that one first. Only one thing can download at a time on the iPad so that could be what is causing the problem.
    If that doesn't work - sign out of your account, restart the iPad and then sign in again.
    Settings>iTunes & App Store>Apple ID. Tap your ID and sign out. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Go back to Settings>iTunes & App Store>Sign in and then try to update again. Tap one waiting icon only if necessary to start the download stream.

  • I have an ipod touch 5th gen and when connected to itunes i get a message saying itunes was unable to load data class information from sync services. reconnect or try again later. anyone got any ideas? i've tried most things on most forums but still no jo

    i have an ipod touch 5th gen and when connected to itunes i get a message saying itunes was unable to load data class information from sync services. reconnect or try again later. anyone got any ideas? i've tried most things on most forums but still no joy

    Try here:
    iTunes for Windows: "Unable to load data class" or "Unable to load provider data" sync services alert
    If not successful see the previous discussion on the right side of this page with the green checkmark.

  • ERRORS found during the burning process #-34506...any idea what this means?

    ERRORS found during the burning process #-34506...any idea what this means?
    This one project I want to copy to DVD keeps saying this when I go to burn (that is after nearly 2 hrs of processing). There is nothing wrong with the movie so i don't know why i'm having such a problem burning it. i guess to start i'd need to know what this code means (I couldn't find it in iDVD help).
    thanks in advance
    Jeremiah

    First I'd be certain that I had changed the preferences from best quality to best performance.
    Did you follow the chapter rules?
    *Make sure no chapter markers are within two seconds of the start or end of the timeline.
    *Make sure no chapter markers are within a transition.
    *Make sure no chapter markers are within two seconds of the end of a transition.
    You may have already done this, but
    Quit iDVD. Search for the file named com.apple.iDVD.plist and trash it. (A new one will be created next launch of iDVD.) Or look in: User/Library/Preferences. This may solve project loading errors too. Restart and use Disk Utility to Repair Permissions.
    :)Sue

  • The crop tool in my tool bar is not showing up. Any ideas why this is? Please Help

    The crop tool in my tool bar is not showing up. Any ideas why this is? Please Help

    It's the 3rd one on Photoshop standard.  As Curt implies, each little icon position has several possibilities you can display, allowing you some customization of your Tools panel.  Click and hold the mouse button to see each of the choices.
    -Noel

  • I just upgraded my software to OS X 10.9.2 (13C64) and i can no longer use my printer (epsun stylus sx235w).  any ideas why this would happen?

    i just upgraded my software to OS X 10.9.2 (13C64) and i can no longer use my printer (epsun stylus sx235w).  any ideas why this would happen?

    Mavericks is the name of your operating system. It is otherwise known as OSX 10.9.
    The previous versions were indeed "cat things".
    The way you would know if you need to download new software from Epson is to go the Epson website and search for your printer there, look for downloads, and see if they have new software listed for 10.9.
    You can revert your system back to what it was two weeks ago. This would be easier to do if you have a backup that you made prior to installing Mavericks (like with Time Machine). If you don't have a backup (sounds like you probably don't), you can look here for some directions about how to go back to the "Cat Thing" that you had prior to installing Mavericks: How to revert OS X back from Mavericks: Apple Support Communities
    If all of this is too hard for you, you could take your Mac in to your Apple store and ask them to help you.

  • Any idea what this query is trying to do?

    Do you guys have any idea what this query(used for report generation) is used for? I don't understand the WHERE clause of this query especially what the Pipe operators(|| ' 21:00:00') are used for?
    SELECT c.course_id,
           mph.subject
    from   courses c, main_pgm_hdr mph
    where
    c.classid=mph.classid
        AND
        TO_CHAR(MPH.CLOSE_DATE, 'mm/dd/yyyy hh24:mi:ss') >= TO_CHAR(TRUNC(SYSDATE, 'MM') - 1, 'mm/dd/yyyy')
            || ' 21:00:00'
        AND TO_CHAR(MPH.CLOSE_DATE, 'mm/dd/yyyy hh24:mi:ss') <= TO_CHAR(SYSDATE, 'mm/dd/yyyy')
            || ' 20:59:59'Edited by: user10450365 on Jan 13, 2009 7:11 PM

    They are trying to get the data having CLOSE_DATE between 20:59:59 and 21:00:00 for the present day. But the way its done is wrong. They have converted the date into Char and they are comparing. Its absolutely incorrect.
    One way to do it would be
    SELECT DISTINCT (PS.CARR_ID)                                  AS CARRIER  ,
         MPH.SHPMT_NBR                                          AS TRAILER  ,
         MPH.SHPMT_NBR                                          AS SHPMT_NBR,
         TO_CHAR(MPH.CREATE_DATE_TIME, 'mm/dd/yyyy hh24:mi:ss') AS LOADED   ,
         TO_CHAR(MPH.CLOSE_DATE, 'mm/dd/yyyy hh24:mi:ss')       AS FINALIZED
       FROM PARCL_SERV PS,
         MANIF_PARCL_HDR MPH
      WHERE PS.MANIF_TYPE = MPH.MANIF_TYPE
        AND MPH.CLOSE_DATE >= TRUNC(sysdate)+(21/24)
        AND MPH.CLOSE_DATE <= TRUNC(sysdate)+((20/24)+(59/1440)+(59/86400))Edited by: Karthick_Arp on Jan 13, 2009 1:27 AM

  • HT3275 iMac.sparsebundle" is already in use  ...any idea what this is ?

    iMac.sparsebundle” is already in use  ...any idea what this is ?

    If you are running Mountain Lion and getting this message when trying to backup,  try this:
    Open AirPort Utility (If you are in Mountain Lion this will be 6.0 or Higher)
    Select you Time Capsule
    Select the Disk Tab
    Deselect "Enable File Sharing"
    Click OK Let the Time Capsule Re-Boot
    Go Back into AirPort Utility and re-select "Enable File Sharing" and let it Re-Boot again.
    This should fix the problem.
    If you are not running Mountain Lion the advice provided by other should work  (http://pondini.org/TM/C12.html).  The main thing is to reset users.

Maybe you are looking for

  • Loss of 3G for a few hours and then back to Normal?????

    I have a 3GS 16gb phone and this morning, it lost 3G for about 3 hours or so...I called AT&T tech support and they could not do much and thought it may be a SIM card issue. Amazingly, before i could visit the AT&T store, things went back to normal an

  • Clean install windows 8 on Ideapad U310

    Hi guys, I have purchased Ideapad U310 couple of months back with Windows 7 home premium installed. Recently I availed the offer. While trying to make a fresh install of Windows 8 I noticed the C drive is not detected. I could not find any solutions

  • Constantly receive error message from ichat.

    I need help. I have been using Ichat for several years without ANY issue and out of nowhere it will not connect with my chat buddy. I get an error message that asks to report to apple or not. I have reported it over a dozen times and no tone reply???

  • Check info not displayed

    Hi, I'm looking up FBL1N for cleared items for a certain vendor. There are 4 clearing documents with doc type ZP. The payment method for this vendor is Check. The latest two clearing document has check information available (when i click on check inf

  • Purchase order release workflow rule

    Hi , I have made a zcopy of standard workflow(WS20000075) for PO release. My requirement is that there are three level of approvers who have to release the PO. MM consultant says he will assign the approvers for all three levels from SPRO. As per the