Example usage for com.badlogic.gdx.scenes.scene2d.ui TextField setCursorPosition

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui TextField setCursorPosition

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui TextField setCursorPosition.

Prototype

public void setCursorPosition(int cursorPosition) 

Source Link

Document

Sets the cursor position and clears any selection.

Usage

From source file:se.theodor.quiz.TeamsEditingPanel.java

License:Apache License

private static void removeLetters(TextField tf) {
    int cursorPosition = tf.getCursorPosition();
    String input = tf.getText();//from   www.  java  2  s. co m
    char[] allowed = "0123456789".toCharArray();
    char[] charArray = input.toString().toCharArray();
    StringBuilder result = new StringBuilder();
    for (char c : charArray) {
        for (char a : allowed) {
            if (c == a) {
                result.append(a);
            }
        }
    }
    tf.setText(result.toString());
    tf.setCursorPosition(cursorPosition);
}

From source file:se.theodor.quiz.TeamsPanel.java

License:Apache License

private void removeLetters(TextField tf) {
    int cursorPosition = tf.getCursorPosition();
    String input = tf.getText();//  w ww.ja  v a  2 s  . c  o m
    char[] allowed = "0123456789".toCharArray();
    char[] charArray = input.toString().toCharArray();
    StringBuilder result = new StringBuilder();
    for (char c : charArray) {
        for (char a : allowed) {
            if (c == a) {
                result.append(a);
            }
        }
    }
    tf.setText(result.toString());
    tf.setCursorPosition(cursorPosition);
}