Row and Col count
Hi guys... i am using a Text Plane as my GUI component ...
How can i get the row count and column count of the current caret location.
Hi guys... i am using a Text Plane as my GUI component ...
How can i get the row count and column count of the current caret location.
int pos = textpane.getCaretPosition();
Document doc = textpane.getDocument();
Element root = doc.getRootElements()[0];
for (int row = 0; row < root.getElementCount(); row++) {
Element line = root.getElement(row);
int start = line.getStartOffset();
int end = line.getEndOffset();
if(pos >= start && pos < end){
int column = pos-start;
System.out.println("["+row+","+column+"]");
break;
}
}
Did you bother searching the forums first?
The keywords to use are already in your question. Words like "row column" and the component name you are using.