This document discusses JavaFX event handling, controls, and components. It describes how JavaFX is used to build rich internet applications that can run across multiple platforms. It explains that GUI applications in JavaFX use events to detect user interactions. Common layouts in JavaFX like BorderPane, HBox, VBox, StackPane, and GridPane are demonstrated along with an example of how to create and configure each one. The document also provides a code sample of using a FlowPane layout.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
129 views
Java FX Event Handling, Controls and Components
This document discusses JavaFX event handling, controls, and components. It describes how JavaFX is used to build rich internet applications that can run across multiple platforms. It explains that GUI applications in JavaFX use events to detect user interactions. Common layouts in JavaFX like BorderPane, HBox, VBox, StackPane, and GridPane are demonstrated along with an example of how to create and configure each one. The document also provides a code sample of using a FlowPane layout.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12
Java FX Event Handling,
Controls and Components
Nithya K Java FX • JavaFX is a Java library used to build Rich Internet Applications. • The applications written using this library can run consistently across multiple platforms. • The applications developed using JavaFX can run on various devices such as Desktop Computers, Mobile Phones, TVs, Tablets, etc.. • To develop GUI Applications using Java programming language, the programmers rely on libraries such as Advanced Windowing Tool kit and Swing. • After the advent of JavaFX, these Java programmers can now develop GUI applications effectively with rich content. Event • In JavaFX, we can develop GUI applications, web applications and graphical applications. In such applications, whenever a user interacts with the application (nodes), an event is said to have been occurred. • For example, clicking on a button, moving the mouse, entering a character through keyboard, selecting an item from list, scrolling the page are the activities that causes an event to happen. Event generated on one of the scene graph node Layouts Steps to create layout In order to create the layouts, we need to follow the following steps. • Instantiate the respective layout class, for example, HBox root = new HBox(); • Setting the properties for the layout, for example, root.setSpacing(20); • Adding nodes to the layout object, for example, root.getChildren().addAll(<NodeObjects>); Border Pane BorderPane BPane = new BorderPane(); BPane.setTop(new Label("This will be at the top")); BPane.setLeft(new Label("This will be at the left")); BPane.setRight(new Label("This will be at the Right")); BPane.setCenter(new Label("This will be at the Centre")); BPane.setBottom(new Label("This will be at the bottom")); Scene scene = new Scene(BPane,600,400); primaryStage.setScene(scene); primaryStage.show(); HBox Button btn1 = new Button("Button 1"); Button btn2 = new Button("Button 2"); HBox root = new HBox(); Scene scene = new Scene(root,200,200); root.getChildren().addAll(btn1,btn2); primaryStage.setScene(scene); primaryStage.show(); VBox Button btn1 = new Button("Button 1"); Button btn2 = new Button("Button 2"); VBox root = new VBox(); Scene scene = new Scene(root,200,200); root.getChildren().addAll(btn1,btn2); primaryStage.setScene(scene); primaryStage.show(); Stack Pane Button btn1 = new Button("Button 1 on bottom "); Button btn2 = new Button("Button 2 on top"); StackPane root = new StackPane(); Scene scene = new Scene(root,200,200); root.getChildren().addAll(btn1,btn2); primaryStage.setScene(scene); primaryStage.show(); GridPane Label first_name=new Label("First Name"); Label last_name=new Label("Last Name"); TextField tf1=new TextField(); TextField tf2=new TextField(); Button Submit=new Button ("Submit"); GridPane root=new GridPane(); Scene scene = new Scene(root,400,200); root.addRow(0, first_name,tf1); root.addRow(1, last_name,tf2); root.addRow(2, Submit); primaryStage.setScene(scene); primaryStage.show(); Flow Pane primaryStage.setTitle("FlowPane Example"); FlowPane root = new FlowPane(); root.setVgap(6); root.setHgap(5); root.setPrefWrapLength(250); root.getChildren().add(new Button("Start")); root.getChildren().add(new Button("Stop")); root.getChildren().add(new Button("Reset")); Scene scene = new Scene(root,300,200); primaryStage.setScene(scene); primaryStage.show();