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

G4P TextArea reading back text broken into lines

$
0
0

hello there, I have a G4P TextArea where I need to 'read back' the text, which is broken into lines according to the wrapWidth parameter. I need to know which part of the text is currently visible in my program. Is there any way to do this, I tried something like this:

  String[] paragraphs = loadStrings("book3.txt");
  startText = PApplet.join(paragraphs, '\n');

  // Create a text area

  txaSample = new GTextArea(this, 80, 20, 290, 300, G4P.SCROLLBARS_BOTH | G4P.SCROLLBARS_AUTOHIDE);
  txaSample.setText(startText, 200);  //wrapWidth: 200

  StyledString tsa=txaSample.getStyledText();

  //can read number of lines correctly:
  print("number of lines: ");println(tsa.getNbrLines());
  //returns the original # of lines only:
  int a=tsa.getPlainTextAsArray().length;
  print("plaintext:");println(a);

  //trying getLines(), does not work:
  //   'cannot cast from PGraphics to Graphics2d'

  Graphics2D g2 = (Graphics2D) g;
  print(tsa.getLines(g2));

I'm really stuck on this, any help greatly appreciated


Viewing all articles
Browse latest Browse all 2896

Trending Articles