Set border width GTextArea

edited November 2016 in Library Questions

Hello,

I have a question about the GTextArea from the G4P library: Is it possible to set the border/stroke width of a GTextArea? If I create a GTextArea, the border/stroke is 5px, but I want that to be 1px.

Thanks in advance Daantje

Answers

  • Answer ✓

    Is is not possible for the user to set the border width of a GTextArea.

    G4P uses double buffering for all its visual controls to improve efficiency so when you specify the size of the control you are actually specifying the size of the graphic-buffer. This buffer is only updated when the visual representation of the control has to change e.g. mouse moving over a button, a key typed into a text area etc otherwise the buffer is simply copied onto the sketch display.

    The 'border' of the GTextArea is simply the background colour used for the buffer and the white area for the text is drawn on top. So one solution is to make the background opaque and draw your own border.

    This small sketch shows what I mean

    import g4p_controls.*;
    
    GTextArea txa1, txa2; 
    
    public void setup(){
      size(480, 320, JAVA2D);
      txa1 = new GTextArea(this, 40, 40, 130, 130, G4P.SCROLLBARS_NONE);
      txa1.setOpaque(false);
      txa2 = new GTextArea(this, 230, 40, 160, 80, G4P.SCROLLBARS_NONE);
      txa2.setOpaque(false);
    }
    
    public void draw(){
      background(192);
      drawBorder(txa1);
      drawBorder(txa2);
    }
    
    void drawBorder(GTextArea txa){
      pushStyle();    // Save all the current drawing variables for later restoration
      rectMode(CORNER);
      strokeWeight(1);
      stroke(255,0,255);
      noFill();
      rect(txa.getX()+4, txa.getY()+4, txa.getWidth()-9, txa.getHeight()-9);
      popStyle();     // Restore all the drawing variables
    }
    

    I have designed the drawBorder method so that it can be called from anywhere inside draw without affecting any other drawing commands

  • That solves the problem :D Thank you very much!!!

    Daantje

Sign In or Register to comment.