Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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(){ public void handle(WindowEvent e){ Alert alert = new Alert(AlertType.INFORMATION, "Thank you for using finder"); alert.setHeaderText("Thank you!"); alert.showAndWait(); System.exit(1); } } ); }

//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 { @Override public void handle(ActionEvent event) { // TODO Auto-generated method stub String findWord = findField.getText(); int index = textArea.getText().indexOf(findWord); if (index != -1) { textArea.selectRange(index, index+findWord.length()); textArea.requestFocus(); } else { alert("Error", "No Match found", AlertType.ERROR); } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions