⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e974. using a position in a jtextcomponent.txt

📁 这里面包含了一百多个JAVA源文件
💻 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 + -