Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the current line number in netbeans editor

How can I get the line number in which the caret is in NetBeans editor.I am developing a net bean plugin and I need to get the position of the caret( not mouse ).

like image 821
user2327579 Avatar asked Nov 02 '22 18:11

user2327579


1 Answers

Get the current pane from editor cookie you use, e.g:

  try {
        StyledDocument doc = editorCookie.openDocument();
        if (editorCookie != null) {
        JEditorPane[] panes = editorCookie.getOpenedPanes();
        if (panes.length > 0) {
            int linenumber = panes[0].getCaret().getDot();
            doc.insertString( linenumber, "emagenio.com", null );  
        }
    }

Regards, @tmmg

like image 178
Silpion Avatar answered Nov 08 '22 09:11

Silpion