javafx textarea
www.igiftidea.com
In JavaFX, a TextArea
is a user interface control that allows the user to enter and edit multiple lines of text. Here's an example of how to create and use a TextArea
:
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TextArea; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class MyJavaFXApp extends Application { @Override public void start(Stage primaryStage) { // Create a text area and a button TextArea textArea = new TextArea(); Button button = new Button("Submit"); // Set the action to be performed when the button is clicked button.setOnAction(event -> { String text = textArea.getText(); System.out.println("Text entered:\n" + text); }); // Put the text area and button in a layout container HBox hbox = new HBox(10, textArea, button); // Put the layout container in another layout container VBox vbox = new VBox(10, hbox); // Create a scene and set it on the stage Scene scene = new Scene(vbox, 300, 250); primaryStage.setScene(scene); // Show the stage primaryStage.show(); } public static void main(String[] args) { launch(args); } }
In this example, we create a TextArea
and a Button
, and set the action to be performed when the button is clicked using a lambda expression. We then put the TextArea
and Button
in an HBox
layout container, and put the HBox
in a VBox
layout container. Finally, we create a scene with the VBox
layout container and set the scene on the stage. When the user types some text in the TextArea
and clicks the button, the program will print the text to the console.