Quick Contact

    Hibernate

    JavaFXTextArea

    The textarea is an input element using for multiple line information in the web application. It is providing multiple lines of input information from the user and store in the application. It is interacted between user and application using a textarea object and set in the database. It is a multi-line editor to getting more than one line of data from the user through the form and message box in the application. It is the latest version does not allow single-line information in the textarea box.

    Syntax:

    • The JavaFXTextarea needed the Textarea class and their object.
    • This object is connected with the scene graph using a holding layout container.
    • The JavaFXTextarea syntax is below.
    TextAreajfxTextarea = new TextArea();
    VBoxjfxbox = new VBox(jfxTextarea);
    Scene jfxscene = new Scene(jfxbox);
    
    • The JavaFXtextarea sets the text syntax using an object.
    • jfxTextarea.setText(“text_here..”);

    • The JavaFXTextarea returns the text syntax using an object.
    • String textObject = jfxTextarea.getText();

    How JavaFXTextArea function works?
    • Download and Install the JDK and java IDE like eclipse on your computer device.
    • Either add the JavaFX jar files in the library or install e(fx) clipse software in java IDE with the latest version.
    • The start method is added to setup the JavaFX Application with the Stage object.
    public class MainClass extends Application{
    @Override
    public void start(Stage jfxStage) throws Exception{
    //Add javaFXTextarea methods and constructor
    }
    }
    
    • Create the Textarea object inside of the start method.
    • The Vbox is a vertical layout container that is useful for textarea.
    • public void start(Stage jfxStage) throws Exception{
      TextAreajfxTextarea = new TextArea();
      VBoxjfxbox = new VBox(jfxTextarea);
      Scene jfxscene = new Scene(jfxbox);
      }
      
    • This object is connected with the scene graph using a holding layout container.
    • public void start(Stage jfxStage) throws Exception{
      TextAreajfxTextarea = new TextArea();
      VBoxjfxbox = new VBox(jfxTextarea);
      Scene jfxscene = new Scene(jfxbox, 320, 160);
      jfxStage.setScene(jfx scene);
      jfxStage.show(); }
      
    • It is used start() and main method to launch the application.
    • public class MainClass extends Application{
      @Override
      public void start(Stage jfxStage) throws Exception{
      TextAreajfxTextarea = new TextArea();
      VBoxjfxbox = new VBox(jfxTextarea);
      Scene jfxscene = new Scene(jfxbox, 320, 160);
      jfxStage.setScene(jfxscene);
      jfxStage.show(); }
      }
      public static void main(String[] args) {
      Application.launch(args);
      }
      }
      

    Constructors

    • The JavaFX used stage constructor to show the window in the desktop application.
    • The Stage constructor is working as a container to hold the application.
    • The theoretical constructor and its object creating syntax is below.
    • Stage jfxstage = new Stage();

    • The JavaFX constructor and its object always passing through the start() method.
    • public void start(Stage jfxStage){ implementation code.. }

    Methods

    The start() method:

    The start method is the initialized method in the JavaFX application. The start method contains and passes all desktop application objects, methods. The JavaFXtextarea always comes with start() method with the Stage constructor.

    public void start(Stage jfxStage)
    {
    Implementation code...
    }
    

    The launch() method:

    The launch() method is necessary to create an application for desktop using JavaFX. Creates the main method in the class and uses the launch() method with command line arguments.

    public static void main(String[] args) {
    Application.launch(args);
    }
    

    Examples of JavaFXTextArea

    Let us discuss examples of JavaFXTextArea.

    Example #1: Basic JavaFXTextarea Example

    package application;
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.TextArea;
    import javafx.scene.layout.VBox;
    import javafx.stage.Stage;
    public class Main extends Application {
    @Override
    public void start(Stage jfxStage) throws Exception {
    TextAreajfxtextArea = new TextArea();
    VBoxjfxvbox = new VBox(jfxtextArea);
    Scene jfxscene = new Scene(jfxvbox, 200, 100);
    jfxStage.setScene(jfxscene);
    jfxStage.show();
    }
    public static void main(String[] args) {
    Application.launch(args);
    }
    }
    

    Description:

    • The textarea creates an object and connecting in the vertical box container.
    • The Vbox is interacted with the Scene node to contain Javafxtextarea.

    Example #2: Label and Padding

    Code:

    package application;
    import javafx.application.Application;
    import javafx.geometry.Insets;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.TextArea;
    import javafx.scene.layout.VBox;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    public class Main extends Application {
    @Override
    public void start(Stage jfxstage) throws Exception {
    Label jfxlabel = new Label( "Write below" );
    TextAreajfxarea = new TextArea();
    jfxarea.setPrefColumnCount(15);
    jfxarea.setPrefHeight(120);
    jfxarea.setPrefWidth(300);
    VBoxjfxbox = new VBox();
    jfxbox.setSpacing(20);
    jfxbox.setPadding(new Insets(20, 50, 50, 60));
    jfxbox.getChildren().addAll(jfxlabel, jfxarea);
    Scene jfxscene = new Scene(jfxbox, 590, 230);
    jfxstage.setTitle( "JavaFXTextArea" );
    jfxstage.setScene(jfxscene);
    jfxstage.show();
    }
    public static void main(String[] args) {
    Application.launch(args);
    }
    }
    

    Description:

    • The setPadding() and setSpacing() methods are used to create the required space between textarea and container.
    • The setPrefHeight() and setPrefWidth() method create required height and width of textarea.

    Example #3: Set and return information

    Code:

    package application;
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.geometry.Insets;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.control.TextArea;
    import javafx.scene.layout.VBox;
    import javafx.stage.Stage;
    public class Main extends Application {
    @Override
    public void start(Stage jfxstage) throws Exception {
    VBoxjfxvbox = new VBox();
    jfxvbox.setPadding(new Insets(10));
    jfxvbox.setSpacing(5);
    Label jfxlabel = new Label("Write Something");
    TextAreajfxtextArea = new TextArea();
    jfxtextArea.setText("write below.\n");
    Button jfxbutton = new Button("Click Here");
    jfxbutton.setOnAction(new EventHandler< ActionEvent>() {
    @Override
    public void handle(ActionEvent event) {
    jfxtextArea.setText("write JavaFxTextarea information.\n");
    String jfxtext = jfxtextArea.getText();
    jfxtextArea.appendText( jfxtext);
    }
    });
    jfxvbox.getChildren().addAll(jfxlabel, jfxtextArea,jfxbutton);
    Scene jfxscene = new Scene(jfxvbox, 360, 250);
    jfxstage.setTitle("JavaFXTextArea window");
    jfxstage.setScene(jfxscene);
    jfxstage.show();
    }
    public static void main(String[] args) {
    Application.launch(args);
    }
    }
    

    Example #4: Current Date

    Code:

    package application;
    import java.util.Date;
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.geometry.Insets;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.control.TextArea;
    import javafx.scene.layout.VBox;
    import javafx.stage.Stage;
    public class Main extends Application {
    @Override
    public void start(Stage jfxstage) throws Exception {
    VBoxjfxvbox = new VBox();
    jfxvbox.setPadding(new Insets(10));
    jfxvbox.setSpacing(5);
    Label jfxlabel = new Label("Enter Date here..");
    TextAreajfxtextArea = new TextArea();
    jfxtextArea.setText(" Current Date: \n ");
    VBoxjfxhbar = new VBox();
    Button jfxbutton = new Button("Date");
    jfxbutton.setOnAction(new EventHandler< ActionEvent>() {
    @Override
    public void handle(ActionEvent event) {
    jfxtextArea.appendText( new Date().toString());
    jfxtextArea.appendText("\n");
    }
    });
    jfxhbar.getChildren().addAll(jfxbutton);
    jfxvbox.getChildren().addAll(jfxlabel, jfxtextArea, jfxhbar);
    Scene jfxscene = new Scene(jfxvbox, 360, 250);
    jfxstage.setTitle("JavaFXTextArea window");
    jfxstage.setScene(jfxscene);
    jfxstage.show();
    }
    public static void main(String[] args) {
    Application.launch(args);
    }
    }
    

    Apply now for Advanced Java Training Course

    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.