Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can somebody help me figure out the code for Main.fxml for the Main.java code below: import javafx.application.Application; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent;

Can somebody help me figure out the code for Main.fxml for the Main.java code below:

import javafx.application.Application; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class Main extends Application { private final TableView table = new TableView<>(); private final ObservableList data = FXCollections.observableArrayList(new Person("A", "B")); final HBox hb = new HBox(); public static void main(String[] args) { launch(args); } public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setWidth(450); stage.setHeight(550); TableColumn firstNameCol = new TableColumn("First Name"); firstNameCol.setMinWidth(100); firstNameCol.setCellValueFactory( new PropertyValueFactory<>("firstName")); TableColumn middleNameCol = new TableColumn("middle Name"); middleNameCol.setMinWidth(100); middleNameCol.setCellValueFactory( new PropertyValueFactory<>("middleName"); TableColumn lastNameCol = new TableColumn("Last Name"); lastNameCol.setMinWidth(100); lastNameCol.setCellValueFactory( new PropertyValueFactory<>("lastName")); table.setItems(data); table.getColumns().addAll(firstNameCol,middleName,lastNameCol); final Button addButton = new Button("Add"); addButton.setOnAction((ActionEvent e) -> { data.add(new Person("Z","X")); }); hb.getChildren().addAll(addButton); hb.setSpacing(3); final VBox vbox = new VBox(); vbox.setSpacing(5); vbox.setPadding(new Insets(10, 0, 0, 10)); vbox.getChildren().addAll(table, hb); ((Group) scene.getRoot()).getChildren().addAll(vbox); stage.setScene(scene); stage.show(); } public static class Person { private final SimpleStringProperty firstName; private final SimpleStringProerty middleName; private final SimpleStringProperty lastName; private Person(String fName,String Mname,String lName) { this.firstName=new SimpleStringProperty(fName) this.middleName = new SimpleStringProperty(MName); this.lastName = new SimpleStringProperty(lName); } public String getFirstName() { return firstName.get(); } public void setFirstName(String fName) { firstName.set(fName); } 
 public String getMiddlename() { return middleName.get(); } public void setMiddleName(String mName) { middleName.set(mName); } 
 public String getLastName() { return lastName.get(); } public void setLastName(String lName) { lastName.set(lName); } } } 

Thank you in advance!

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

Budgeting A Comprehensive Guide

Authors: Steven M. Bragg

5th Edition

1642210463, 978-1642210460

Students also viewed these Databases questions