📄 e974. using a position in a jtextcomponent.txt
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -