user2327579
user2327579

Reputation: 499

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 ).

Upvotes: 5

Views: 929

Answers (1)

Silpion
Silpion

Reputation: 99

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

Upvotes: 2

Related Questions