![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e974. Using a Position in a JTextComponentA position marks a location between two characters in aJTextComponent . 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, 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();
e969. Retrieving All the Text from a JTextComponent Efficiently e970. Modifying Text in a JTextComponent e971. Asynchronously Reading the Contents of a Visible JTextComponent e972. Finding Word Boundaries in a JTextComponent e973. Retrieving the Visible Lines in a JTextComponent e975. Limiting the Capacity of a JTextComponent e976. Enabling Text-Dragging on a JTextComponent e977. Sharing a Document Between JTextComponents e978. Enumerating All the Views in a JTextComponent
© 2002 Addison-Wesley. |