AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
appendText (Object comp, String str [, int offset [, int adjust [, Pointer undo]]]) yoix.swing
 
Updates the AWT or Swing component comp by appending str to the text already displayed by that component and returns the number of characters that were added to the displayed text. If the component maintains a text insertion point (e.g., the caret when comp is a JTextArea, JTextField, TextArea or TextField) then appendText also tries to position it at the end of the appended text.

The optional offset argument gives you control over where str goes in the existing text. The optional adjust argument should be 1 when you want appendText to try to position the caret (if there is one) at the end of the appended text, and 0 otherwise. The optional undo argument should be a pointer to an Array with room for at least three elements that appendText uses to return information (two integers and a string) that can be used to undo the operation. The first element in the array is the offset where the operation took place, the second element is the number of new characters that were added at that offset, and the last element is a String that is the text that was replaced by the operation, which in the case of appendText will always be the empty string. The order of the elements in the undo array make it particularly easy to use with unroll and replaceText.

appendText works with any AWT or Swing component that defines a field named text. As you might expect, appendText often produces results that match

comp.text += str;
but it usually is more efficient and does a better job for components, like a TextArea or JTextPane, that do more than simply draw the characters in a string.
 
 Example:   The following example displays a frame containing a textarea and a button. Pressing the button appends more text to the textarea and positions the caret at the end of that text.
import yoix.*.*;

JFrame f = {
    Dimension size = NULL;

    Array layout = {
        new JTextArea {
            String tag = "$_textarea";
            String text = "Spam, spam, spam, baked beans, sausage and spam";
            int    textwrap = TRUE;
            int    rows = 8;
            int    columns = 50;
            int    scroll = VERTICAL;
        }, CENTER,

        new JButton {
            String text = "More Spam";

            actionPerformed(ActionEvent e) {
                appendText(root.components.$_textarea, ", spam");
                root.components.$_textarea.requestfocus = TRUE;
            }
        }, SOUTH,
    };
};

f.visible = TRUE;
The line that requests the focus for the textarea is only included to make it easy to see the caret position.
 
 Return:   int
 
 See Also:   JTextArea, JTextField, JTextPane, TextArea, TextField, TextTerm, deleteText, insertText, replaceText, unroll

 

Yoix is a registered trademark of AT&T Inc.