Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

G4P GtextArea scrolling to bottom as you type

$
0
0

I am trying to figure out a way to scroll down to the last line of the GTextArea after each time text is set.

If you try my code you can see when the text reaches the bottom of the view nothing happens. I tried using getTextAsArray in combination with moveCaretTo in order to place caret at the end of the text, hoping it would scroll down. But getTextAsArray always returns an array with only one element, even after text goes to a new line.

   import g4p_controls.*;
   import g4p_controls.GCScheme;
   import java.awt.Font;
   import java.awt.*;

   GTextArea textArea;
   String txtMain ="";
   int screenWidth;
   int screenHeight;

   void setup() {
     screenWidth = 400;
     screenHeight = 300;
     size(screenWidth, screenHeight, JAVA2D);
     smooth();
     background(255);

     textArea = new GTextArea(this, 5, 0, screenWidth - 10, screenHeight);
     textArea.setFont(new Font("", Font.PLAIN, 80));
     textArea.setText("", screenWidth - 20);
     textArea.setTextEditEnabled(false);
   }

   void draw() {
     background(255);
    }

   void keyPressed() {
     txtMain = txtMain + key;
     textArea.setText(txtMain);
   }

Viewing all articles
Browse latest Browse all 2896

Trending Articles