As said from the title, I'm trying to get text that you put in a textArea component, and save it to a variable. But, it's giving me a NullPointerException error when I open the screen. I'm using the owolib library.
Here's my code so far:
package org.pyrotonic.simplenotes.client.screen;
import io.wispforest.owo.ui.base.BaseOwoScreen;
import io.wispforest.owo.ui.component.Components;
import io.wispforest.owo.ui.component.TextAreaComponent;
import io.wispforest.owo.ui.container.Containers;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.core.*;
import io.wispforest.owo.ui.core.Insets;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
public class TestScreen extends BaseOwoScreen<FlowLayout> {
@Override
protected @NotNull OwoUIAdapter<FlowLayout> createAdapter() {
return OwoUIAdapter.create(this, Containers::verticalFlow);
}
@Override
protected void build(FlowLayout rootComponent) {
String textContent = rootComponent.childById(TextAreaComponent.class, "text-test").getText();
rootComponent.surface(Surface.VANILLA_TRANSLUCENT);
rootComponent
.surface(Surface.VANILLA_TRANSLUCENT)
.horizontalAlignment(HorizontalAlignment.CENTER)
.verticalAlignment(VerticalAlignment.CENTER);
rootComponent.child(
Containers.verticalFlow(Sizing.content(), Sizing.content()))
.child(Components.textArea(Sizing.fixed(10), Sizing.fixed(10), "Text"))
.child(Components.button(Text.literal("Print Text"), buttonComponent -> {System.out.println(textContent);}))
.padding(Insets.of(10))
.surface(Surface.DARK_PANEL)
.verticalAlignment(VerticalAlignment.CENTER)
.horizontalAlignment(HorizontalAlignment.CENTER)
.id("text-test");
}
}
Here's a log of me trying to open the screen: https://mclo.gs/ISAbNqu