Skip to content

#08.6 TextArea (Outdated)

Valkryst edited this page Jul 18, 2018 · 1 revision
import com.valkryst.VTerminal.Panel;
import com.valkryst.VTerminal.builder.PanelBuilder;
import com.valkryst.VTerminal.builder.component.TextAreaBuilder;
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 TextAreaBuilder textAreaBuilder = new TextAreaBuilder();
        textAreaBuilder.setPosition(10, 10);

        textAreaBuilder.setWidth(20);
        textAreaBuilder.setHeight(3);

        textAreaBuilder.setMaxHorizontalCharacters(40);
        textAreaBuilder.setMaxVerticalCharacters(6);

        panel.addComponents(textAreaBuilder.build());

        panel.draw();
    }
}

Code Explanation

final TextAreaBuilder textAreaBuilder = new TextAreaBuilder();

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

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


textAreaBuilder.setPosition(10, 10);

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


textAreaBuilder.setWidth(20);
textAreaBuilder.setHeight(3);

This sets the text area to be 20 cells wide and 3 cells tall.


textAreaBuilder.setMaxHorizontalCharacters(40);
textAreaBuilder.setMaxVerticalCharacters(6);

This tells the builder that we want to be able to enter 40 characters per line and that we want to be able to enter 6 lines.

So, in the previous step we set the width and height to 20 and 3, but in this step we're saying that we want to be able to enter double those amounts. The width and height set both the minimum/visible number of characters per line and number of lines, whereas the max horizontal/vertical characters set both the maximum number of characters per line and maximum number of lines.

The text area will scroll itself to allow you to edit these additional characters/lines.


panel.addComponents(textAreaBuilder.build());

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

Result