title: Get the index of selected text using JEditorPane
body: <p>How to get the index of selected text using <code>JEditorPane</code>?</p>
  
  <p>I am trying to get the starting and ending index of selected text in editor pane. </p>
  
  <p>When I select the text in editor pane,  the index returned by editor pane is different from the index of string in actual HTML file. When I select  a single line text then both indexes are same but if I select multiple line then indexes are different. </p>
  
  <p>I am using the following code.</p>
  
  <pre><code>int start = editorpane.getSelectionStart();
  int end = editorpane.getSelectionEnd();
  JOptionPane.showMessageDialog(null, "Start index "+ start);
  JOptionPane.showMessageDialog(null, "End index "+end);
  </code></pre>
  
  <p>It return smaller index. </p>
  
  <p>when using the following code its returning the actual index but i want   the same index in   above code.</p>
  
  <pre><code> try
     {
      File f1= new File("path of the file");
      FileReader fin= new FileReader(f1);
      BufferedReader br= new BufferedReader(fin);
      String s=br.readLine();
      String con="";
      while(s!=null)
      {
      con=con+s;
      s=br.readLine();
  
      }
      int l=con.lastIndexOf("CASE CITED");
  
      System.out.println("index="+l);
  
  
     }
     catch(Exception ex){}
  
  }              
  </code></pre>