Reputation: 499
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
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