Column number of caret position

How can I get column number of caret position. Of course I can use
  int dot = editorPane.getCaret().getDot();
  Element root = editorPane.getDefaultRootElement
  int lineIndex = root.getElementIndex(dot);
  Element lineElement = root.getElement(lineIndex);
  int lineStartOffset = lineElement.getStartOffset();
  int column = dot - lineStartOffset + 1;
to find the column in a unidirectional text! But what I should do for bidirectional text that has Hebrew, Arabic, or another RTL language? Also with a monospaced font the code
  int dot = editorPane.getCaret().getDot();
  double x = editorPane.modelToView(dot).getX();
  int column = (int) x / someFontMetrics.stringWidth("0") + 1; This won't help anymore. What should I do? The code
  editorPane.getUI().modelToView(editorPane, dot, dotBias) won't work too. First because the dotBias cann't be accessed in DefaultCaret. Second in some cases it probably won't solve the problem.

Thanks Stats! It won't work!
Hmmm.... Actually many unicode characters have no width, such as \u064E (Arabic Fatha). Some of them are only for visual ordering purpose, such as \u202A (Left to Right Embedding).
Paying more attention to English letters, we'll notice ligatures used in some fonts. For instance occurrence of the letters fi (f and i) will produce the one letter fi (\uFB01).
We saw the algorithm you suggest won't work even for English text! Two ways we have. (In fact these are two mthods I can suggest!)
1. Using the final output after affecting ligatures and bidirectional algorithm, finding the position of the desired character!
2. Using xy position of the caret and derive the column number for a fixed font.
Actually I want to use the second way though the first one is easier and more efficient. That's it! All I want is just the xy position of the caret!
But ANY IDEA?!

Similar Messages

  • Getting the row and column number from the caretposition

    Howdy peeps
    Does anyone know how to find out the Line number and column in a JTextPane by using the caret position
    (you know like in text editors where it says 100:4 [line number:character position on row])
    is there a simple way of doing this in a JTextPane?

    im getting a bit confuzzled with this :(
    can someone help me out with a bit more code orientated help? :$
    i have a jTextArea and a JTextField, when i change the caret in the text area i want the JTextField to show the line number and charater position on the row (e.g. 100:4)
    so i assume i need to methods
    e.g.
    getPaneRow
    myint=myPane.getCaretPosition()
    do some wonderful magic code to get the line number
    return line number
    getPaneColumn
    myint=myPane.getCaretPosition()
    do some wonderful magic code to get the column number
    return column number
    is there a magician out there that can give me the magic powder? :)

  • How to update caret position in status bar ?

    Hello, I'm trying to display 'Line Number & Position' in my status bar, I'm not sure how to proceed from here.
    How would I update this to occur on every keystroke?
    SSCCE
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.event.KeyEvent;
    import javax.swing.BorderFactory;
    import javax.swing.Box;
    import javax.swing.JFrame;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextField;
    import javax.swing.JTextPane;
    import javax.swing.border.EtchedBorder;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.Element;
    import javax.swing.text.Utilities;
    public class test extends JFrame
         private static final long serialVersionUID = 1L;
         private JTextPane pane;
         @SuppressWarnings("unused")
         public static void main(String[] args)
              test t = new test();
         public test()
              super("test");
              this.setDefaultCloseOperation(EXIT_ON_CLOSE);
              this.setLayout(new BorderLayout());
              this.add(textPane(), BorderLayout.CENTER);
              this.add(statusBar(), BorderLayout.SOUTH);
              this.pack();
              this.setVisible(true);
         private JTabbedPane textPane()
              pane = new JTextPane();
              JTabbedPane tab = new JTabbedPane();
              tab.addTab("  Query  ", null, pane, "Query");
              tab.setMnemonicAt(0, KeyEvent.VK_1);
              return tab;
         private Box statusBar()
              Box sBar = Box.createHorizontalBox();
              JTextField linePosField = new JTextField(15);
              linePosField.setBackground(Color.LIGHT_GRAY);
              linePosField.setEditable(false);
              linePosField.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
              linePosField.setText(String.format("%s %d %s %d", "Line:",
                        getCaretRowPosition(pane), "Pos:",
                        getCaretColumnPosition(pane)));
              sBar.add(linePosField);
              return sBar;
          * Return the current line number at the Caret position.
         public int getCaretRowPosition(JTextPane textPane)
              int caretPosition = textPane.getCaretPosition();
              Element root = textPane.getDocument().getDefaultRootElement();
              return root.getElementIndex( caretPosition ) + 1;
          * Return the current Caret position.
         public int getCaretColumnPosition(JTextPane textPane)
              int offset = textPane.getCaretPosition();
              int column;
              try {
                   column = offset - Utilities.getRowStart(textPane, offset);
              } catch (BadLocationException e) {
                   column = -1;
              return column;
    }Edited by: G-Unit on Oct 17, 2010 4:08 AM

    Sorry, Found CaretListener(): Updated code;
    private JTabbedPane textPane()
       pane = new JTextPane();
       pane.addCaretListener(new CaretListener() {
          public void caretUpdate(CaretEvent e)
             linePosField.setText(String.format("%s %d %s %d", "Line:",
                getCaretRowPosition(pane), "Pos:",
                getCaretColumnPosition(pane)));
       JTabbedPane tab = new JTabbedPane();
       tab.addTab("  Query  ", null, pane, "Query");
       tab.setMnemonicAt(0, KeyEvent.VK_1);
       return tab;
    }Now I just have to figure out how to add a panel for line number to sit adjacent to my text area without throwing the whole window out of proportion. I tried adding some context menu buttons to sit next to it, and for some reason they seemed to want to grow by 500x the size specified and destroyed the whole look of the app. :s maybe I will just make do with status bar line numbers.
    Edited by: G-Unit on Oct 17, 2010 4:35 AM

  • Number line and position in the line

    Hi, is it possible to know the number of the line and the position of the cariet in a textarea?

    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    public class UTextComponent
         **  Return the current column number at the Caret Position.
         public static int getColumnAtCaret(JTextComponent component)
              int caretPosition = component.getCaretPosition();
              Element root = component.getDocument().getDefaultRootElement();
              int line = root.getElementIndex( caretPosition );
              int lineStart = root.getElement( line ).getStartOffset();
              return caretPosition - lineStart + 1;
         **  Return the current line number at the Caret position.
         public static int getLineAtCaret(JTextComponent component)
              int caretPosition = component.getCaretPosition();
              Element root = component.getDocument().getDefaultRootElement();
              return root.getElementIndex( caretPosition ) + 1;
         **  Return the number of lines of text.
         public static int getLines(JTextComponent component)
              Element root = component.getDocument().getDefaultRootElement();
              return root.getElementCount();
         **  Position the caret at the start of a line.
         public static void gotoLine(JTextComponent component, int line)
              Element root = component.getDocument().getDefaultRootElement();
              line = Math.max(line, 1);
              line = Math.min(line, root.getElementCount());
              component.setCaretPosition( root.getElement( line - 1 ).getStartOffset() );
              //  The following will position the caret at the start of the first word
              try
                   component.setCaretPosition(javax.swing.text.Utilities.getNextWord(component, component.getCaretPosition()));
              catch(Exception e) {System.out.println(e);}
         **  Return the number of lines of text, including wrapped lines.
         public static int getWrappedLines(JTextPane component)
              int lines = 0;
              View view = component.getUI().getRootView(component).getView(0);
              int paragraphs = view.getViewCount();
              for (int i = 0; i < paragraphs; i++)
                   lines += view.getView(i).getViewCount();
              return lines;
         public static void main(String[] args)
              final JTextPane textComponent = new JTextPane();
    //          final JTextArea textComponent = new JTextArea(5, 30);
    //          textComponent.setLineWrap( true );
              textComponent.addCaretListener( new CaretListener()
                   public void caretUpdate(CaretEvent e)
                        System.out.println
                             "Column/Line : " +
                             UTextComponent.getColumnAtCaret( textComponent ) +
                             "/" +
                             UTextComponent.getLineAtCaret( textComponent ) +
                             ", Lines : " +
                             UTextComponent.getLines( textComponent ) +
                             ", Wrapped Lines : " +
                             UTextComponent.getWrappedLines( textComponent )
                        SwingUtilities.invokeLater( new Runnable()
                             public void run()
                                  System.out.println( UTextComponent.getWrappedLines( textComponent ) );
              JScrollPane scrollPane = new JScrollPane( textComponent );
              JPanel panel = new JPanel();
              panel.add( new JLabel( "Goto Line:" ) );
              final JTextField gotoField = new JTextField(4);
              panel.add( gotoField );
              gotoField.addActionListener( new java.awt.event.ActionListener()
                   public void actionPerformed(java.awt.event.ActionEvent e)
                        UTextComponent.gotoLine(textComponent, Integer.parseInt( gotoField.getText()) );
                        gotoField.setText("");
                        textComponent.requestFocus();
              JFrame frame = new JFrame( "Text Component Utilities" );
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              frame.getContentPane().add( scrollPane );
              frame.getContentPane().add(panel, java.awt.BorderLayout.SOUTH);
              frame.pack();
              frame.setVisible(true);
    }

  • Is caret positioning in right-to-left oriented jtextpane corruptable?

    Dear all -
    Below is a serious problem. I hope I can get help from you experts out there; otherwise, I think it is a bug that should be reported to the JDK developers.
    I am writing an editor using my own keyboard layout to type in Arabic. To do so, I use jTextPane, and my own implementation of DocumentFilter (where I map English keys to Arabic letters). I start by i) setting the component orientation of jTextPane to be from RIGHT_TO_LEFT, and ii) attaching a caretListener to trace the caret's position.
    The problem (I think it is a bug just like what is recorded here: http://bugs.adobe.com/jira/browse/SDK-16315):
    Initially as I type text in Arabic, there is one-to-one correspondence between where I point my mouse and where the caret displays, basically, the same place. However, a problem occurs (and can always be re-produced) when I type a word towards the end of the line, follow it by a space character, and that space character causes the word to descend to the next line as a result of a wrap-around. Now, as I point my mouse to that first line again, the location where I click the mouse and the location where the caret flashes are no longer coincident! Also, the caret progression counter is reversed! That is, if there are 5 characters on Line 1, then whereas initially the caret starts from Position 0 on the right-hand side and increases as more text is added from right to left, it is now reversed where the the caret now increases from left to right for the first line, but correctly increases from right to left in the second line! yes funny stuff and very hard to describe to.
    So, here is an example. I wrote the code below (JDK1.6_u10, on Netbeans 6.5 RC2) to make it easy to reproduce the problem. In the example, I have replaced the keys A, S, D, F and G with their Arabic corresponding letters alif, seen, daal, faa and jeem. Now, type these letters inside the double quotes (without the double quotes) including the two spaces please and watch out for the output: "asdfg asdfg ". Up until you type the last g and before you type space, all is perfect, and you should notice that the caret position correctly moves from 0 upwards in the printlines I provided. When you type that last space, the second word descends as a result of the wrap-around, and hell breaks loose! Notice that whereas the mouse and caret position are coincident on the second line, there is no way to fine-control the mouse position on the first line any more. Further, whereas adding text on the second line is intuitive (i.e., you can insert more text wherever you point your mouse, which is also where the caret would show up), for the first line, if you point the mouse any place over the written string, the caret displays in a different place, the any added text is added in the wrong place! All this because the caret counter is now reversed, which should never occur. Any ideas or fixes?
    Thank you very much for reading.
    Mohsen
    package workshop.onframes;
    import java.awt.ComponentOrientation;
    import java.awt.Rectangle;
    import javax.swing.event.CaretEvent;
    import javax.swing.event.CaretListener;
    import javax.swing.text.BadLocationException;
    public class NewJFrame1 extends javax.swing.JFrame {
    public NewJFrame1() {
    initComponents();
    jTextPane1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    CaretListener caretListener = new CaretListener() {
    public void caretUpdate(CaretEvent e) {
    int dot = e.getDot();
    int mark = e.getMark();
    if (dot == mark) {
    try {
    Rectangle cc = jTextPane1.modelToView(dot);
    System.out.println("Caret text position: " + dot +
    ", view location (x, y): (" + cc.x + ", " + cc.y + ")");
    } catch (BadLocationException ble) {
    System.err.println("CTP: " + dot);
    } else if (dot < mark) {
    System.out.println("Selection from " + dot + " to " + mark);
    } else {
    System.out.println("Selection from " + mark + " to " + dot);
    jTextPane1.addCaretListener(caretListener);
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
    jScrollPane3 = new javax.swing.JScrollPane();
    jTextPane1 = new javax.swing.JTextPane();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jTextPane1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
    jTextPane1.setAutoscrolls(false);
    jTextPane1.addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyTyped(java.awt.event.KeyEvent evt) {
    jTextPane1KeyTyped(evt);
    jScrollPane3.setViewportView(jTextPane1);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
    .addContainerGap())
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    pack();
    }// </editor-fold>
    private void jTextPane1KeyTyped(java.awt.event.KeyEvent evt) {
    if (evt.getKeyChar() == 'a') {
    evt.setKeyChar('\u0627');
    } else if (evt.getKeyChar() == 's') {
    evt.setKeyChar('\u0633');
    } else if (evt.getKeyChar() == 'd') {
    evt.setKeyChar('\u062f');
    } else if (evt.getKeyChar() == 'f') {
    evt.setKeyChar('\u0641');
    } else if (evt.getKeyChar() == 'g') {
    evt.setKeyChar('\u062c');
    public
    static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new NewJFrame1().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration
    }

    Hi Mohsen,
    I looked at it and indeed, I see what you describe. Sorry, but I can't shed any light. I tried to figure out what software component, or combination of components, is the cause of the problem. I see several candidates:
    1) The JTextPane
    2) The Document
    3) RTL support
    4) BIDI support
    5) Interpretation (by any other software component) of the left and right arrow key
    6) The font
    To clarify number 6: I know virtually nothing of Arabic language (apart from it being written from right to left). I remember however that the actual representation of a letter is dependent of its position between other letters: front, middle and end. What I see to my astonishment is that it seems that the rendering is also aware of this phenomenon. When you insert an A between the S and D of ASDFG, the shape of the S changes. Quite magic.
    I tried to add a second textpane with the same Document, but a different size, to see what would happen with number one if one types text in number two and vice versa.
    In my first attempt, the font that you set on textpane one was gone after I set its document to number two. For me that is very strange. The font was set to the textpane, not to the document. The separation betweem Model and View seems not very clear in this case. So I now also set that font on the second textpane.
    I will post the changed code so that you may experiment some more and hopefully will find the problem.
    You might be interested in a thread on java dot net forums that discusses a memory leak for RTL [http://forums.java.net/jive/message.jspa?messageID=300344#300344]
    Piet
    import java.awt.ComponentOrientation;
    import java.awt.EventQueue;
    import java.awt.Font;
    import java.awt.Rectangle;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import javax.swing.GroupLayout;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextPane;
    import javax.swing.WindowConstants;
    import javax.swing.event.CaretEvent;
    import javax.swing.event.CaretListener;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.Document;
    public class NewJFrame1 extends JFrame {
        private static final long serialVersionUID = 1L;
        public NewJFrame1() {
         initComponents();
         // jTextPane1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
         this.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
         CaretListener caretListener = new CaretListener() {
             public void caretUpdate(CaretEvent e) {
              int dot = e.getDot();
              int mark = e.getMark();
              if (dot == mark) {
                  try {
                   Rectangle cc = jTextPane1.modelToView(dot);
                   System.out.println("Caret text position: " + dot
                        + ", view location (x, y): (" + cc.x + ", "
                        + cc.y + ")");
                  } catch (BadLocationException ble) {
                   System.err.println("CTP: " + dot);
              } else if (dot < mark) {
                  System.out.println("Selection from " + dot + " to " + mark);
              } else {
                  System.out.println("Selection from " + mark + " to " + dot);
         jTextPane1.addCaretListener(caretListener);
        private KeyAdapter toArabic = new KeyAdapter() {
         public void keyTyped(KeyEvent evt) {
             jTextPane1KeyTyped(evt);
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
        // @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
         jScrollPane3 = new JScrollPane();
         jTextPane1 = new JTextPane();
         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
         jTextPane1.setFont(new Font("Tahoma", 0, 24)); // NOI18N
         jTextPane1.setAutoscrolls(false);
         jTextPane1.addKeyListener(toArabic);
         jScrollPane3.setViewportView(jTextPane1);
         GroupLayout layout = new GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
         layout.setHorizontalGroup(layout.createParallelGroup(
              GroupLayout.Alignment.LEADING).addGroup(
              layout.createSequentialGroup().addContainerGap().addComponent(
                   jScrollPane3, GroupLayout.DEFAULT_SIZE, 159,
                   Short.MAX_VALUE).addContainerGap()));
         layout.setVerticalGroup(layout.createParallelGroup(
              GroupLayout.Alignment.LEADING).addGroup(
              layout.createSequentialGroup().addContainerGap().addComponent(
                   jScrollPane3, GroupLayout.PREFERRED_SIZE, 85,
                   GroupLayout.PREFERRED_SIZE).addContainerGap(
                   GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
         pack();
        }// </editor-fold>
        private void jTextPane1KeyTyped(KeyEvent evt) {
         if (evt.getKeyChar() == 'a') {
             evt.setKeyChar('\u0627');
         } else if (evt.getKeyChar() == 's') {
             evt.setKeyChar('\u0633');
         } else if (evt.getKeyChar() == 'd') {
             evt.setKeyChar('\u062f');
         } else if (evt.getKeyChar() == 'f') {
             evt.setKeyChar('\u0641');
         } else if (evt.getKeyChar() == 'g') {
             evt.setKeyChar('\u062c');
        public static void main(String args[]) {
         EventQueue.invokeLater(new Runnable() {
             public void run() {
              final NewJFrame1 frameOne = new NewJFrame1();
              frameOne.setLocationRelativeTo(null);
              frameOne.setVisible(true);
              EventQueue.invokeLater(new Runnable() {
                  public void run() {
                   Document doc = frameOne.jTextPane1.getDocument();
                   JTextPane textPane2 = new JTextPane();
                   textPane2.setFont(new Font("Tahoma", 0, 24)); // NOI18N
                   textPane2.setAutoscrolls(false);
                   textPane2.setDocument(doc);
                   textPane2.addKeyListener(frameOne.toArabic);
                   JFrame frameTwo = new JFrame();
                   frameTwo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   frameTwo.add(new JScrollPane(textPane2));
                   frameTwo.setSize(400, 300);
                   frameTwo.setLocationByPlatform(true);
                   frameTwo.setVisible(true);
                   frameTwo
                        .applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        // Variables declaration - do not modify
        private JScrollPane jScrollPane3;
        private JTextPane jTextPane1;
        // End of variables declaration
    }

  • Column number in JTextArea?

    Hi
    How do I get column number of current cursor
    in JTextArea? I need to display this info
    in my editor.
    This is complicated by the fact that tab size
    is not fixed, typing a combination of space
    and tabs randomly can result in tabs
    having tab size of 1 amid normal tabs.
    Hence counting the number of chars in the
    current line up to cursor position, call it C,
    then C minus number of tabs, T and plus
    T * tabSize won't work because tabSize is
    sometimes 1.
    Thanks
    miawomi

    Hello
    Just figure out how to do this. In case anyone
    get stuck with the same problem, here is my
    soln:
    JTextArea textArea = ...
    int caretPos = textArea.getCaretPosition();
    int lineCount = textArea.getLineCount();
    int tabSize = textArea.getTabSize();
    int currentLine = 1;
    String str = "";
    int c = 0;
    try {
    currentLine = textArea.getLineOfOffset( caretPos );
    int startOffset =
    textArea.getLineStartOffset (currentLine );
    str = textArea.getText( startOffset,
    caretPos-startOffset );
    FontMetrics fm = textArea.getFontMetrics( textArea.getFont() );
                        StringBuffer buffer = new StringBuffer();
    for ( int i = 0; i < tabSize; i++ )
    buffer.append(" ");
    int tabWidth = fm.stringWidth( buffer.toString() );
    for ( int i = 0; i < str.length(); i++ ) {          char C = str.charAt( i );
                             if ( fm.charWidth( C ) == tabWidth )
                                  c = c + tabSize;
                             else
                                  c++;
                   } catch ( BadLocationException ex ) {
                        ex.printStackTrace();
    If anyone has a much less cpu intensive solution,
    please let me know.
    Thanks in advance
    miaw

  • Why order by clause maintains column number values instead of column names

    why order by clause maintains column number values instead of column names ?

    we can use oder by 1,2 as column number
    UGNo one said that it can't be used. What's your point?
    To OP: It can be written with the column's 'select list positional number' just because for the support of laziness. :)
    There's no difference between 'ORDER BY name, address' and 'ORDER BY 1,2'.

  • Getting to know caret position

    when backspace is keyed, is there a way to know whether the caret in a textPane has return to the previous line??
    e.g
    the caret is at the beginning of line 2 of the textpane... by keying backspace,the caret will return to line 1.. is there a way to know that the caret has return to the previous line?

    The following code will tell you the current line number of the caret. So you will need to add some before/after logic to tell if the line number has changed:
    **  Return the current line number at the Caret position.
    public static int getLineAtCaret(JTextComponent component)
         int caretPosition = component.getCaretPosition();
         Element root = component.getDocument().getDefaultRootElement();
         return root.getElementIndex( caretPosition ) + 1;
    }

  • Displaying the Row and Column number in the report

    I am trying to show row and column number in the report (not just web preview). I am using Hyperion Reports Version 7.2.5.168

    use a formula column/row. use RANK function in that. (e.g. Rank([A], asc) will sort the rows based on column A values in ascending order)
    you can use this rank in your heading.
    But frankly this is not so easy. You have to do it in a very intelligent way, so that rank gives you column number/row number any how.
    Have a try and let see if you find a appropriate solution.
    Regards,
    Rahul

  • Find caret position of search text in jEditorPane

    Hi All,
    I am looking for a way to find the Caret position in a jeditor pane for the search text that i supply. The Jeditor pain is setup for text/html and when i find the index of my search text "ANCHOR_d" in the jeditor pane is 27000 something but the caret position is 7495 how do you find the caret position of the search text ??
    Any help is appriciated.
    I am also looking into getting abnchoring to work in the jeditorpane html text but as of yet i have been unsuccessful.
    Kind Regards,
    Wurns

    Search the underlying document, not the editor pane. Play around with this example, which I threw together the other day for a somewhat similar problem with JTextPane involving newlines, and modified for your need.
    Note: Please do not program by exception.import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import javax.swing.JButton;
    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    import javax.swing.text.Document;
    public class SearchEditorPane {
       JFrame frame = new JFrame ("Search JTextPane Test");
       String html = "<HTML><BODY><P>This is <B>some</B>" +
                    " <I>formatted</I>" +
                    " <FONT color=#ff0000>colored</FONT>" +
                    " html.</P>" +
                    "<P>This is a <FONT face=Comic Sans MS>" +
                    "comic <br>\n<br>\nsans ms</FONT> section</P><div>" +
                    "And this is a new division</div>" +
                    "</BODY></HTML>";
       JEditorPane editorPane = new JEditorPane ("text/html", html);
       JPanel panel = new JPanel ();
       JTextField textField = new JTextField (10);
       JButton button = new JButton ("Find");
       Document doc = editorPane.getDocument ();
       void makeUI () {
          editorPane.setText ("<HTML><BODY><P>This is <B>some</B>" +
                " <I>formatted</I>" +
                " <FONT color=#ff0000>colored</FONT>" +
                " html.</P>" +
                "<P>This is a <FONT face=Comic Sans MS>" +
                "comic <br>\n<br>\nsans ms</FONT> section</P><div>" +
                "And this is a new division</div>" +
                "</BODY></HTML>");
          button.addActionListener (new ActionListener () {
             public void actionPerformed (ActionEvent e) {
                // Programming by exception is BAD, don't copy this style
                // This is just to illustrate the solution to the problem at hand
                // (Sorry, uncle-alice, haven't reworked it yet)
                try {
                   Matcher matcher = Pattern.compile (textField.getText ())
                   .matcher (doc.getText (0, doc.getLength ()));
                   matcher.find ();
                   editorPane.setCaretPosition (matcher.start ());
                   editorPane.moveCaretPosition (matcher.end ());
                   editorPane.requestFocus ();
                } catch (Exception ex) {
                   JOptionPane.showMessageDialog (frame, "Not Found!\n" + ex.toString ());
                   //ex.printStackTrace();
          panel.add (textField);
          panel.add (button);
          panel.setPreferredSize (new Dimension (300, 40));
          frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
          frame.setSize (300, 300);
          frame.add (editorPane, BorderLayout.CENTER);
          frame.add (panel, BorderLayout.SOUTH);
          frame.setLocationRelativeTo (null);
          frame.setVisible (true);
       public static void main (String[] args) {
          SwingUtilities.invokeLater (new Runnable () {
             public void run () {
                new SearchEditorPane ().makeUI ();
    }db

  • JEditorPane: transforming between caret position in html and text/plain

    Hi all,
    I've done quite a bit of searching, and found problems similar to this one, but not this exactly, so I'll try asking it here.
    I have a JEditorPane with HTMLEditorKit, which I'm using for a WYSIWYG text editor. When the user wants to insert something, say an image, I get the caret position and insert a String into the document's underlying text.
    The problem is that if we are the WYSIWYG mode, the caret position isn't the same as the caret position in text/plaain mode.
    So if the underlying text is
    <html>
      <body>
         Some text
      </body>
    </html>the user will just see "Some text". If they place the caret between "Some" and "text", editorPane.getSelectionStart() will return '5'. But I want to insert my text at position '16' in the plain text.
    Is there a simple way to go back and forth between these two positions? Or to have getSelectionStart() to return the index relative to the text/plain mode?
    Thanks!
    Tim

    Very poor that no one answered this one.
    Did you still need the answer?
    I have 'a' answer. But not a complete one.
    In fact I only found this in search for an answer for my problem:
    http://forums.sun.com/thread.jspa?threadID=5409216&tstart=0
    Did you actually just test out what you knew so far to test what happens?
    If you were to use the HTMLEditorKit.insertHTML function, it just wants the visual caret position. So '5' would have been reasonably correct for you.
    I was doing something like this:
                   HTML.Tag tag = null;
                   Pattern p = Pattern.compile("\\s*\\<\\s*(\\w+).*", Pattern.MULTILINE|Pattern.DOTALL);
                   Matcher m = p.matcher(text);
                   if (m.matches())
                        tag = HTML.getTag(m.group(1));
                   kit.insertHTML(doc, offset,// +1
                                  text, 0,// 0
                                  0,// 0
                                  tag);
    Assuming you were inserting a tag, my code there checks what tag it is, and if that is known by the java implementation, assigns that to 'tag', so that the element is correctly inserted.
    If it is not known, we just use 'null'. Which for me wasn't such a great result.
    In fact, nothing really was a great result, as with the default java implementation being buggy (so far as I can see) it inserted to the wrong position and caused all sorts of anomalies.
    Hope you worked it out. And if you did, and have a better result than what I have, maybe you can let me know what you did!
    Sincerely,
    sean

  • Setting Caret Position

    Dears,
    How do I set the Caret position to a required position in the SpinnerNumberModel? Do I need to use setDot() and NavigationFilter? The position should be set as soon as Spinner is constructed.
    Please help.
    Thanks,
    Raj

    Hi,
    I didn't get it work too, but this workaround seems to work.
    Cheers
    import javafx.application.Application;
    import javafx.application.Platform;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.scene.Scene;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    public class CaretPositioner extends Application {
         public static void main(String[] args) {
              Application.launch((java.lang.String[]) null);
         @Override
         public void start(Stage primaryStage) {
              BorderPane root = new BorderPane();
              final TextField tf = new TextField();
              tf.textProperty().addListener(new ChangeListener<String>() {
                   @Override
                   public void changed(ObservableValue<? extends String> arg0, String arg1, String arg2) {
                        System.out.println(tf.getCaretPosition());
                        Platform.runLater(new Runnable() {
                             @Override
                             public void run() {
                                  tf.positionCaret(0);
              root.setCenter(tf);
              Scene scene = new Scene(root);
              primaryStage.setScene(scene);
              primaryStage.show();
    }

  • Summary Links web part not showing correct column number

    Here is my scenario. I have a simple two server dev farm that is using a snapshot of production data. I have migrated the 2010 content db over and everything is running fine. One quirk I have noticed is with the summary links web part. If I add the webpart
    to a page, in the configuration settings for the webpart you can create named groups and the next setting is how many columns you want the links to appear in. When I select lets say "4" columns, and I create four groups. When I save and check in
    the web part only shows "3" columns instead of 4. 
    For Example. 
    I create groups: Group 1
                              Group 2
                              Group3 
                              Group 4
    In the webpart configuration I select "display number of columns" = 4
    When I save that setting and look at the web part the groups will appear as:
     Group 1             Group 2                    Group 3
    Group 4
    when in reality if the column setting is = 4, I would expect: 
    Group 1      Group 2      Group 3      Group 4
    So it appears it is behaving as if whatever column number you select, what is displayed is N-1. 
    Has anyone else had this happen in SharePoint 2013? The same webpart doesn't behave this way in the 2010 production environment where dev gets its content. Any help would be great. 
    Thanks,

    Hi againeyuga,
    Yes, I have tested in my SharePoint Server 2013 with December 2013 CU  and it  works fine. For your environment, I recommend  you install the SP1 update.
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • Get the raw/column number of a left-mouse clicked table cell

    is this possible to get the row/column number of
    a cell where a mouse is clicked? Accutally, i want to implement a
    dynamic one column list which the user can "Add" or "Delete" some entries. The
    "Add" function is all right. The "Delete" function
    makes me upset because I cannot catch the cell's location where the
    mouse is choosing. I tries to use "Active Cell", it seems does not
    work. Do you have any clue? is this possible to implement the dynamic list using the "listbox"? thanks

    I would use the EditPos property value.  In my testing, it always returned the row and column of the cell I had left-clicked on.

  • Purchase order row basecard column number

    hi
    any one help me what is purchase order row basecard column number.
    Thanks & Best Regards
    B.Lakshmi narayanan

    Hi,
    Could you clarify your reguest?
    Thanks,
    J.

Maybe you are looking for

  • I received a pop-up saying I need to ask you for the 64-bit version of flash player

    I keep getting this pop-up how can I get rid of it I tried to download flash player last week and now it says it is incompatibile

  • AUSOUG/OAUG 2006 Australian conference - database content

    The AUSOUG and OAUG committees are very excited to announce the Australian 2006 conference series is less than three months away. While our American neighbours are focusing on Oracle OpenWorld in October, and our UKOUG friends on their (extended!) No

  • Elements 12 wont update

    I get a notification Elements & Premiere 12 that updates are available. After downloading the files i get an update errer when trying to install them.

  • Add product

    Imports System.Data.SqlClient Public Class frmProduct     Dim intDB_SKU_Selected As String     Dim intDB_Supplier_Selected As Integer     Dim intEdit_ID As String     Dim operation_save As String     Public Sub ClearTextBox()         txtSKU.Clear()  

  • QM Procedure for Delivering Order

    hi all i have made order confirmation for fg material and now i want to make delivery for it. i have maintain inspction plan : with group conter 3 having usage 6. so now i want material to be inspected before delivery. so please can anybody what will