JeditorPane text selection problem due to line feeds and carriage returns

Hi folks,
I have a jEditorPane (text/plain) that contains a document in which the user has highlighted some text. I want to pull the selected text from the pane, do some processing on it, and then put the altered text back in the same position.
First I get the starting and ending position of the highlighted text
int mySelStart = myJEditorPane.getSelectionStart();
int mySelEnd = myJEditorPane.getSelectionEnd();Then I get all the text from the pane and (in theory) strip out the portion the user highlighted
String myPaneText = myJEditorPane.getText();
String mySelectedText = myPaneText.substring(mySelStart,mySelEnd);But the text string in mySelectedText never matches what the user originally highlighted. The starting and ending positions are off by the number of carriage returns that proceed the highlighted text in the document. It appears that while in the jEditorPane Java treats the carriage return as one characters, but once the info is in the myPaneText field Java treats the carriage return as two characters.
Has anyone encountered this before? Am I doing something wrong? To fix the problem I'm looping through the entire document to find out how many carriage returns proceed the highlighted text, but there has to be an easier way.
Thanks

It appears that while in the jEditorPane Java treats the carriage return as one
characters, but once the info is in the myPaneText field Java treats the carriage
return as two characters.Correct on a Windows platform. Check out my posting here for a one line solution:
http://forum.java.sun.com/thread.jspa?forumID=31&messageID=1464594

Similar Messages

  • How do I add either a line Feed or Carriage Return to a column?

    I am using
    "Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production"
    "PL/SQL Release 11.2.0.1.0 - Production"
    "CORE 11.2.0.1.0 Production"
    "TNS for Linux: Version 11.2.0.1.0 - Production"
    "NLSRTL Version 11.2.0.1.0 - Production"
    I would like to know when merging two results like so:
    select
         'Answer: ' || answer_value || 'Date: ' || date || 'Name' || name_value as notes
    from table
    to show as in the column:
    Answer: B
    Date: 07-11-2013
    Name: Johnny
    I get something like this
    Answer: B Date: 07-11-2013 Name: Johnny
    Is there a way to use Line Feed or Carriage Return?
    I tried using the char(10) but did not work.
    Also where are the instruction to be able to place the query into a format to allow others to see? Originally I learned to use code { } on this site, but they changed it.
    example:
    select
    'Answer: ' || answer_value || 'Date: ' || date || 'Name' || name_value as notes
    Testing it above.
    Plus what happened to the preview button to see if I posted it correctly?
    The section on" how to ask a question "did not have much about this.

    You may be going about this the wrong way.  Such formatting is normally left to the reporting tool.
    Embedding formatting junk (like cr/lf) in your data is not a good idea.  Not only does it not belong there, but it might not always work.  CR and/or LF are platform specific.

  • Trying to capture line feed or carriage return

    We have a socket application. We would like to know what is the line terminating character? Below is a snippet of codes. Any comments if this is right?
    BufferedReader readerBuffer = null;
    readerBuffer = new BufferedReader(new InputStreamReader(sockConn1.getInputStream()));
    int readChar=0;        
    while ((readChar=readerBuffer.read()) != -1)
         System.out.println("Read char "+(char) nextChar); 
    }

    Below is the full codes without the db connection and processing as we see that will be too long here.
    public class deviceServer {
      class deviceConnectionHandler implements Runnable {
        private Socket sockConn1;
        deviceConnectionHandler(Socket receivedSocketConn1) {
          this.sockConn1=receivedSocketConn1;
         Connection dbConnection = null;
         Statement dbStmt = null;
         public void run() {
         String completeMessage="";
         BufferedReader readerBuffer = null;    
        BufferedWriter writeBuffer = null;
         try {
             readerBuffer = new BufferedReader(new InputStreamReader(sockConn1.getInputStream()));
             writeBuffer = new BufferedWriter(new OutputStreamWriter(sockConn1.getOutputStream()));
             int readChar=0;        
             sockConn1.setSoTimeout(120000);
           //dbConnection = connectionPool.getConnection();
             //dbConnection.setAutoCommit(false);
                 while ((readChar=readerBuffer.read()) != -1)
                           System.out.println("Read Char : "+(char) readChar);
                           completeMessage += (char) readChar; 
                         if (readChar == '*') {
                         try {
                          writeBuffer.write("@@\r\n\r\n");
                         writeBuffer.flush();                    
                          //db processing
                           dbConnection.commit();
                        catch (SQLException ex){
                             ex.printStackTrace();
                                try{   
                                    dbConnection.rollback(); 
                                    catch (Exception rollback){   
                                         rollback.printStackTrace();
                         catch (Exception e){
                               e.printStackTrace(System.out);
                                   try{   
                                    dbConnection.rollback(); 
                                    catch (Exception rollback){   
                                         rollback.printStackTrace(System.out);
                         finally{
                                try{
                                     if ( dbStmt != null ){
                                       dbStmt.close();
                                catch(SQLException ex){
                                ex.printStackTrace(System.out);
                       completeMessage="";          
               catch (SocketTimeoutException ex){
                    ex.printStackTrace();
               catch (IOException ex){
                    ex.printStackTrace();
               catch (Exception ex){
                    ex.printStackTrace();
               finally{
                 try{
                      if ( dbConnection != null ){
                        dbConnection.close();
                 catch(SQLException ex){
                     ex.printStackTrace();
                 try{
                     if ( writeBuffer != null ){
                             writeBuffer.close();
                 catch(IOException ex){
                    ex.printStackTrace(System.out);
       public static void main(String[] args) {
          new deviceServer();
       deviceServer() {
          /*try {
          // setup the connection pool
          catch (SQLException e) {
             e.printStackTrace(System.out);
          try{
                final ServerSocket serverSocketConn = new ServerSocket(7000);                    
                while (true){
                   try{
                       Socket socketConn1 = serverSocketConn.accept();
                     new Thread(new deviceConnectionHandler(socketConn1)).start();                          
                   catch(Exception e){
                      e.printStackTrace();
          catch (Exception e){
             e.printStackTrace();
    }

  • New line character and carriage return in XML, please help, thanks

    In XML, "
" is only the new line character. I have tried that. If you put that in your XML, for example:
    <tag>line1&#10;line2&#10;line3</tag>
    You will get the output as follow:
    line1
    ____line2
    ________line3
    (where ___ represents space)
    The output that I want is actually like:
    line1
    line2
    line3
    So I would like to ask how I can do this.
    Thanks,
    Jackie

    while parsing your XML file you can directly suppress these newline and similar things in characters() method of SAX parser.
    you can opt to do nothing when you encounter them else if it is normal character then use it to print it.

  • Please explain me how I can use Form feed(\f) and Carriage return(\r)

    what is Form feed(\f) and Carriage return(\r)?
    Please explain to me.
    Thank you.

    These control characters aren't used much these days except that if you example a Windows or MSDOS text file in a binary editor you'll find each line ends with "\r\n". However when reading or writing text through classes these carriage returns will be added and removed automatically so your program doesn't see them.
    The controlls date back to teletype machines which operated rather like typewriters. Cariage return, as it's name implied, caused the print head to move back to the start of the line, line feed advanced a line (without, necessarilly, returning the carriage) and formfeed skipped to the next page.
    Newline on these machines was always "return, linefeed" because executing the carriage return on these machine could take too long. The early machines had only a single character buffer so that they had to executed the characters as quickly as they arrived. So doing the linefeed after the carriage return gave the carriage more time to return. On some teletypes if you did "linefeed, return" then the first character of the new line would often be printed somewhere in the middle of the line.
    This is the origin of the MSDOS/Windows end of line sequence.
    Many printers will still respect formfeed if printing is direct. Some will take carriage return without linefeed to allow you to start again overprinting the same line.
    However printing, these days, is seldom direct but done in bitmap form.

  • Removing new lines and carriage returns

    Hi,
    SO I am new to regular expressions in java and I want to remove all the new lines and carriage returns from some text, and change them into <p>
    I have tried,
    Pattern pat = Pattern.compile("\n");
    Matcher mat = pat.matcher(text);
    StringBuffer sb = new StringBuffer();
    boolean result = mat.find();
    while (result){
    mat.appendReplacement(sb,"<p>");
    result = mat.find();
    mat.appendTail(sb);
    text=sb.toString();
    But it seems to have no effect. Anyone know what I'm doing wrong?
    Cheers
    Sandra

    Hello, i've got the same problem. I want to replace "carriage return" and "new line" from an text file. and i use the replace all function for a String object. The problem is, if i call the replace function like this:
    row = row.replaceAll ("\\r", "<p>");
    The "carriage return" is replaced, but not with the "<p>" characters, only with nothing.
    Lines from my original textfile:
    This is an example.
    I want to replace.
    After replacing with the function call row = row.replaceAll ("\\r", "<p>");
    This is an example.I want to replace.
    What is wrong. If i insert tab spaces and replace them, everything is fine. it is abug in my Java Version?
    I use j2re1.4.2_05
    I hope, anybody can help me

  • XSL and carriage return problem

    I'm using an HTML form to get the input text from the user.
    The text is stored in an XML file and after that I use XSL transformation
    to show the text as HTML file.
    The problem is with carriage returns that user has entered.
    In HTML file I see &#13;
    In my java code I tried to replace all &#13; with <br> but It sounds there is no &#13; when I
    look in my XML content in a java string variable.
    Any Idea?
    Thanks,
    Payam

    Store the user-entered portion in a <![CDATA[Data goes here]]> tag to preserve whitespace and carriage returns.
    - Jesse

  • Forced Line Break and Paragraph Return

    Hi.. It´s maybe a simple question but I cannot see diferences.
    What´s the difference between Forced Line Break and Paragraph Return ?
    Thank's for the answer

    A force line break is still the same paragraph. You won't see a difference unless there is some text change with each new paragraph, such as a style change or the addition of space before or after a paragraph. The forced line break can also be used as a trigger in a nested style to make the first line or lines formatting for a paragraph different from the following lines.
    Peter

  • Migration and Carriage Returns Problem

    I'm trying to migrate from Now Up To Date a Palm based 3rd party app - to Address Book in order to get get ready for and buy an iPhone. But all contacts with carriage returns in my NUTD contacts (doulble address lines and in Notes) look like this in Address Book after importing:
    Title: ¶Description: Serial Number: BD0C159 ¶TSID Number: 10040150 ¶Model: SCSI Card AV-2906¶¶¶
    Instead of:
    Title:
    Description: Serial Number: BD0C159
    TSID Number: 10040150
    Model: SCSI Card AV-2906
    I have over 1000 contacts many of which have carriage returns. Will I have to fix these manually?
    Thx,
    Steven

    Store the user-entered portion in a <![CDATA[Data goes here]]> tag to preserve whitespace and carriage returns.
    - Jesse

  • Carriage Returns, Line Feeds, and Tabs in Text Area

    I am having users copy and paste data from an Excel spreadsheet into a textarea on a BSP page.  When they submit this, since there are tabs and line feeds in the data, the BSP does not recognize the data.  The value in the field comes through as blank. When I manually type something into this field, with out any carriage returns, tabs, etc., the value does not come through as blank?  Does anybody know how to get around this?

    HI
    Iam uploading the data from application server(AL11) to other server.
    In the GLPCA-SGTXT(Table) iam having some text like 'This is good ##'.i was downloded some other data with this text('This is good ##') by using report program in to aplicationserver(AL11) and from there iam uploading that data into other server.
    But here the problem is in the UNIX, it was showing some problem.
    That is actually it need to show the format like:
    001 256 786 This is good## 459786
    But here it was showing like:
    001 256 786 This is good^M
    459786
    So here '459786' is coming to next line. But i need this '459786' also in the same line.
    I am not sure if it is possible to remove CR and LF's using the code the program is written in, but that is what we need to do.   In Unix  ^M is the CR (Carriage return), but I am not sure what LF is?

  • Text selection problem in linked containers

    Hi,
    I get a strange behavior on the selection of text in a textFlow with several linked containers (from the latest SVN version it seems).
    The problem occurs on the following case: http://lafabrick.com/labz/tlfTest/ (source code enabled)
    If I select some text in container D to A (or vice versa): display of text selection is correct.
    The problems are:
    - If I select some text in the containers B or C, and that I move the selection to the right or left: the container is moving ...
    - If I select some text in the containers B or C, and that I move the selection to the up or down: the display of the selection is not normal (I have a "blinking selection")
    TLF version : 502 (715519)
    Regards
    fabien

    Hi Richard,
    Would you like to said that this fixe is not present on the SVN (/trunk) ?
    In this case it's of course a bad news for me: my app can't takes all benefits of TLF for now (and for MAX...).
    But a good news for all ! It means that TLF is perhaps soon to release !
    Thanks a lot.
    Fabien

  • Regarding problem with new line feed for DME file generation

    Hello Experts,
    I m facing a problem in the DME file generation.
    we want each record in the DME file should be in new line. for that we have add the new line feed character in the each row end. So in the SAP output it looks ok, But if we download that file the carriage return field is coming in the end of every row.
    can any one tell how to solve this issue.
    Please refer the below line code which i m using for new line
    DATA: GM_newline TYPE c VALUE cl_abap_char_utilities=>CR_LF
    You reply is valuable..
    Thanks,
    Suresh

    DATA: GM_newline TYPE c VALUE cl_abap_char_utilities=>newline.

  • Text selection problems in Pages on iPad

    I use Pages on an iPad, and have recently been having problems with text selection. If I press the screen on a word, that word goes blue but I can't extend the blue area beyond the single word. Usually the document freezes. Sometimes I can unfreeze it by continuing to press, but I still can't select the area required. Select all works fine. I have tried the same operation in Documents 2, and initially I had the same problem, but then it started working as usual. Has anyone else had the same problem? Advice would be much appreciated.
    Bob Sax

    You probably have floating objects with text wrap on and are hammering away at returns, spaces and tabs to position text. The mix of objects and text are tucking in and around each other in somewhat unpredictable ways.
    Cut the objects and paste them into the text to make them Inline and you might be able to position things more predictably.
    Peter

  • Problem with new-line-character and java.io.LineNumberReader under AIX

    Hi folks,
    I got the following problem: I wrote a little parser that reads in a plain-text, tabulator-separated, line-formatted logfile (and later on safes the data to a 2-dimensional Vector). This logfile was originally generated by an AIX ksh script, however, I copied it on my Windows machine to work with it (for I'm using a Java editor that runs under Win Systems).
    For any reason, Windows, and what is worse Java too, seems not to recognize correctly the new-line character (in the API it is written that this should be a newline '\n' or a carriage-return '\r' or one followed by the other) that marks the end of a line in the logfile.
    Also, when I'm opening the logfile with the "Notepad"-editor, this special character does not seem to be recognized, every line is inserted right after the other.
    On the other side, when I open the logfile with the built-in editor in the CMD-Shell ("Dos-shell"), the newline chars seem to be recognized correctly.
    But when start my parser on the AIX-machine the newline does not seem to be recognized correctly again.
    I tried to read in the logfile with MS-Excel and safe it as a plain-text, tabulator-separated, line-formatted logfile again, with such files my parser works fine both on the AIX as it does on Windows.
    Any ideas? Anybody got over the same problem already?
    Greetz FK

    Under windows, text files' lines are usually delimited by \r\n,
    under Unix/Linux/AIX etc. \n
    and under Mac \r.
    I recommend to use the following editors, which are capable to handle files with Unix and Windows-styled line-delimiters or convert between these types:
    Programmer's File Editor (PFE; available on Windows)
    The Nirvana Editor (http://www.nedit.org/; available on Unix, MAcOS, Windows)
    (BTW good old vim can handle that too. Transferring text files to windows in order to edit them, even using Excel for this purpose means your being a UNIX newbie, (I mean no offense by writing this) so vim is probably beyond your reach for the moment.)
    Java normally assumes the platform's line delimiters where it is running, so if you transferred the file from Unix to Windows might be distrurbing.

  • Find the LINE FEED and replace it.

    Hi
    I am using ORACLE 11g R2. I am having some text data in a variable as below :-
    Variable = V_TEXT
    V_TEXT :=
    '/u01/oracle/data/file1.txt
    /u01/oracle/data/file2.txt
    /u01/oracle/data/file3.txt'I want to place an '|' (pipe symbol) at the end of each line. So the expected output is as below :-
    '/u01/oracle/data/file1.txt|
    /u01/oracle/data/file2.txt|
    /u01/oracle/data/file3.txt|' I tried with replace() function and replaced return character i.e. CHR(10) with '|' but it gives me an wrong output and also at the end of last line we dont have an return character.
    after searching a lot on internet I found that i can do this with the help of regular expression.
    As far as i have studied : -
    The line feed character is the last character in the line or we can say it is end of line. This character is noted in oracle as 'x0a'
    I want to replace this character in every line and place an '|' symbol.
    can anyone guide me how to do it ??
    Thanks in advance.

    Aha... Now that is a different expected output as in your original post ;-)
    One way of doing it could be something like this:
    declare
      v_text varchar2(32767) := '/u01/oracle/data/file1.txt
    /u01/oracle/data/file2.txt
    /u01/oracle/data/file3.txt';
    begin
      v_text := regexp_replace(
                   regexp_replace(v_text,chr(10)||'\s*'||chr(10),chr(10))
                 ,'$','|',1,0,'m'
      dbms_output.put_line(v_text);
    end;
    /Inner regexp replaces "linefeed followed by zero or more whitespace followed by linefeed" with a single linefeed. So this removes the blank lines.
    Then the outer regexp takes care of the | characters.
    (It might be possible to wrap it up in a single regexp, though I can't think of a way just off hand ;-) )

Maybe you are looking for

  • MacBook odd DVI issue

    Hi All, I have a MacBook 2.2 ghz and have been using it successfully with the mini-dvi to dvi-hdmi cable for the past 3 weeks. I have a 50" Panasonic Plasma and it worked great. Yesterday (after not using it for about a week) I plugged it in and my M

  • I can not get into gmail at all, must go to internet explorer since new firefox installed 3.6.15

    There is simply an empty box in where gmail was. If I put it into the address bar, it simply says "stopped". I have to go to internet explorer to check gmail. 3 days now.....

  • Nikon NEF raw files show up in Bridge as "Untagged RGB"

    I have a D700 and shoot in the AdobeRGB color space. However when I click on a picture in Bridge, the Metadata window shows "Untagged RGB". Why is Bridge showing inaccurate file information, and, I assume, not interpreting and displaying the picture

  • Does the calendar have the capability too?

    Several members and I would like to use the Oracle Calendar as a calendar for all of the organizations members to view to see what is happening in each department and when. The organization consists of approximately 10 departments. Each department wo

  • ISDN configuration for backup of backup

    Hello Guys.. I have an MPLS connection where I have running BGP with service provider and I have an ISDN configured (default route with higher AD) as a Backup of that. My customer wants to implement another ISDN connection which should act the backup