e974. using a position in a jtextcomponent.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 18 行
TXT
18 行
A position marks a location between two characters in a JTextComponent. The position attempts to remain between the same two characters despite edits to the JTextComponent. For example, if the position is at location 10 and the first character is deleted, the new location of the position becomes 9.
When text is inserted at the position, a position's bias determines whether it remains in the same location or is moved to the end of the new text. By default, createPosition() returns a position with a right bias, which means inserting text at the position causes it to move to the end of the inserted text. There is no way to change the bias at present.
JTextComponent textComp = new JTextArea();
Document doc = textComp.getDocument();
Position p = null;
try {
// Create a right-bias Position object
int location = 3;
p = doc.createPosition(location);
} catch (BadLocationException e) {
}
// Retrieve the current location of the Position object
int location = p.getOffset();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?