G4P: How can I make text inside editText field be Capital letter?

Hello, I finally make some input field to insert my data but I need my text inside input field shows the only capital letter. No matter I input the text with a capital letter or not.

Example: If I want to type text “hi” or “HI”
I want to show like this.
2

But now my program still show like this if I type text “hi”
1

Can you help me how to make the input text show the only capital letter? Thank you

Ps. From library G4P

1 Like

-a- there is a event ENTERED
that would be after the [enter]
there you can call your own “text mod method”
-b- there is a function
https://processing.org/reference/String_toUpperCase_.html
you can use for this.

/**
 This sketch is to demonstrate some features of GTextArea controls. 
 
 for Processing V2 and V3
 (c) 2015 Peter Lager
 
 */

import g4p_controls.*;

GTextArea txa1;

public void setup() {
  size(500, 300);
  G4P.setGlobalColorScheme(GCScheme.PURPLE_SCHEME);
  txa1 = new GTextArea(this, 10, 10, 480, 280);
  txa1.tag = "txa1";
  txa1.setPromptText("Text area 1");

}

public void draw() {
  background(200, 128, 200);
}

void workOnText() {                      // do something with the text
    println("get text area and check writing and save back ");
    String theText = txa1.getText();
    txa1.setText(theText.toUpperCase());        // change all to big
}

public void displayEvent(String name, GEvent event) {
  String extra = " event fired at " + millis() / 1000.0 + "s";
  print(name + "   ");
  switch(event) {
  case CHANGED:
    println("CHANGED " + extra);
    break;
  case SELECTION_CHANGED:
    println("SELECTION_CHANGED " + extra);
    break;
  case LOST_FOCUS:
    println("LOST_FOCUS " + extra);
    break;
  case GETS_FOCUS:
    println("GETS_FOCUS " + extra);
    break;
  case ENTERED:
    println("ENTERED " + extra);  
    workOnText();                              // add here
    break;
  default:
    println("UNKNOWN " + extra);
  }
}

public void handleTextEvents(GEditableTextControl textControl, GEvent event) { 
  displayEvent(textControl.tag, event);
}

2 Likes

Thank you. You are my life saver.

What is wrong with the Shift or Caps Lock key?