Question
How to change my code so that it uses VBox instead of the GridPane? import javafx.application.Application; import javafx.event.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.control.Alert.*; import
How to change my code so that it uses VBox instead of the GridPane?
import javafx.application.Application; import javafx.event.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.control.Alert.*; import javafx.scene.layout.*; import javafx.stage.*; import javafx.geometry.*;
public class TextFinder extends Application { TextArea textArea; TextField findField;
@Override public void start(Stage stage) { stage.setTitle("Find"); GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); //Text area textArea = new TextArea(""); //textArea.setText(""); textArea.setPrefSize(350, 350); textArea.setWrapText(true); ScrollPane scrollPane = new ScrollPane(textArea); grid.add(scrollPane, 0, 0, 2, 1); //Find label Label findLabel = new Label("Find: "); grid.add(findLabel, 0, 1); //Find text field findField = new TextField(); grid.add(findField, 1, 1); //Find button Button findButton = new Button("Find"); grid.add(findButton, 0, 2); //Clear button Button clearButton = new Button("Clear"); grid.add(clearButton, 1, 2); findButton.setOnAction(new FindAction()); //Clear button action clearButton.setOnAction( actionEvent -> { findField.setText(""); }); Scene scene = new Scene(grid, 350, 400); stage.setScene(scene); stage.show(); //Closing window action stage.setOnCloseRequest( new EventHandler
//Alert message to be displayed if any to the user public void alert(String title, String message, AlertType alertType) { Alert alert = new Alert(alertType); alert.setTitle(title); alert.setHeaderText(null); alert.setContentText(message); alert.showAndWait(); }
//Execution starts from here public static void main(String[] args) { launch(args); } //Named inner class which handles Find event private class FindAction implements EventHandler
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started