![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e968. Retrieving Text from a JTextComponentThis example works for all types of text components.// Create the text component JTextComponent tc = new JTextArea("Initial Text"); // Get length int docLength = tc.getDocument().getLength(); // Get all text String text = tc.getText(); try { // Get the first 3 characters int offset = 0; int len = 3; text = tc.getText(offset, len); // Get the last 3 characters offset = docLength-3; len = 3; text = tc.getText(offset, len); } catch (BadLocationException e) { }
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 e974. Using a Position 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. |