G4P textarea bug?

I used the G4P GUI Builder to create a textarea 'textarea1' but when I use textarea1.insertText("Hello World") it throws up an error Offset out of bounds in TextLayout.getNextRightHit() when the sketch is run.

The setText and appendText methods work correctly.

I'm using the latest versions of Processing, the G4P Library and the G4P GUI Builder tool and in the sample below I didn't modify the code in the gui tab at all.

// Need G4P library
import g4p_controls.*;


public void setup(){
  size(480, 320, JAVA2D);
  createGUI();
  customGUI();
  // Place your setup code here

    textarea1.insertText("Hello World");
}

public void draw(){
  background(230);

}

// Use this method to add additional statements
// to customise the GUI controls
public void customGUI(){

}

The Debugger produces the following output:

===================================================

G4P V4.1.2 created by Peter Lager

java.lang.IllegalArgumentException: Offset out of bounds in TextLayout.getNextRightHit() at java.awt.font.TextLayout.getNextRightHit(TextLayout.java:1445) at java.awt.font.TextLayout.getNextRightHit(TextLayout.java:1481) at g4p_controls.StyledString.getTLHIforCharPosition(Unknown Source) at g4p_controls.StyledString.getTLHIforCharPosition(Unknown Source) at g4p_controls.GTextArea.insertText(Unknown Source) at g4p_controls.GTextArea.insertText(Unknown Source) at g4p_controls.GTextArea.insertText(Unknown Source) at Text_Area_Error_Demo.setup(Text_Area_Error_Demo.java:29) at processing.core.PApplet.handleDraw(PApplet.java:2412) at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547) at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)

Perhaps Quark can help?

Thanks,

Phil.

Answers

  • Answer ✓

    This method is designed to insert text into existing text so you need to set some text (at least 2 characters) BEFORE you can insert text. Try this

    public void setup(){
      size(240, 240, JAVA2D);
      createGUI();
      customGUI();
      // Place your setup code here
      textarea1.setText("abcdefgh");
      textarea1.insertText("Hello World");
    }
    
  • Many thanks Peter. I knew it had to be something simple :x

    Phil.

Sign In or Register to comment.