#08.7 TextField (Outdated) - Valkryst/VTerminal GitHub Wiki

import com.valkryst.VTerminal.Panel;
import com.valkryst.VTerminal.builder.PanelBuilder;
import com.valkryst.VTerminal.builder.component.TextFieldBuilder;
import com.valkryst.VTerminal.font.Font;
import com.valkryst.VTerminal.font.FontLoader;

import java.io.IOException;
import java.net.URISyntaxException;

public class Driver {
    public static void main(final String[] args) throws IOException, URISyntaxException {
        final Panel panel = new PanelBuilder().build();

        final TextFieldBuilder textFieldBuilder = new TextFieldBuilder();
        textFieldBuilder.setPosition(10, 10);
        textFieldBuilder.setWidth(20);
        textFieldBuilder.setMaxHorizontalCharacters(40);

        panel.addComponents(textFieldBuilder.build());

        panel.draw();
    }
}

Code Explanation

final TextFieldBuilder textFieldBuilder= new TextFieldBuilder();

Constructs a new TextFieldBuilder. You can view the documentation here.

You can reuse the builder, so you won't need to create a new TextFieldBuilder every time you want to create a new check box.


textFieldBuilder.setPosition(10, 10);

This tells the builder to place the text area at position (10x, 10y).


textFieldBuilder.setWidth(20);

This sets the text field to be 20 cells wide.


textFieldBuilder.setMaxHorizontalCharacters(40);

This tells the builder that we want to be able to enter 40 characters.

So, in the previous step we set the width to 20, but in this step we're saying that we want to be able to enter double that amount. The width set both the minimum/visible number of characters, whereas the max horizontal characters set the maximum number of characters.

The text field will scroll itself to allow you to edit these additional characters.


panel.addComponents(textFieldBuilder.build());

This builds the text field and adds it to the panel.

Result