List of utility methods to do JTextComponent Column
int | getColumn(int pos, JTextComponent editor) get Column return pos - Utilities.getRowStart(editor, pos) + 1;
|
int | getColumn(JTextComponent editor, int pos) get Column try { return pos - Utilities.getRowStart(editor, pos) + 1; } catch (BadLocationException e) { e.printStackTrace(); return -1; |
int | getColumnAtPosition(JTextComponent editor, int caretPosition) get Column At Position if (editor.getDocument().getLength() == 0) { return 0; if (caretPosition >= editor.getDocument().getLength() - 1) { caretPosition = editor.getDocument().getLength() - 1; while (caretPosition < 0) { try { ... |
int | getColumnNumber(JTextComponent editor, int pos) Gets the column number at given position of editor. if (pos == 0) { return 0; Rectangle r = editor.modelToView(pos); int start = editor.viewToModel(new Point(0, r.y)); int column = pos - start; return column; |
int | getDocumentPosition(JTextComponent editor, int line, int column) Get the closest position within the document of the component that has given line and column. int lineHeight = editor.getFontMetrics(editor.getFont()).getHeight(); int charWidth = editor.getFontMetrics(editor.getFont()).charWidth('m'); int y = line * lineHeight; int x = column * charWidth; Point pt = new Point(x, y); int pos = editor.viewToModel(pt); return pos; |
void | setCaretPosition(JTextComponent target, int line, int column) Sets the caret position of the given target to the given line and column int p = getDocumentPosition(target, line, column);
target.setCaretPosition(p);
|