Create TableView in JavaFX


Create TableView in JavaFX:

________________________________________________

import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.TextFieldTableCell; import javafx.scene.layout.GridPane; import javafx.stage.Stage; public class JavaFXTableView extends Application { @Override public void start(Stage primaryStage) { GridPane pane = new GridPane(); String FNAME = ""; String LNAME = ""; String AGE = ""; String NATIONAL = ""; TableView table = new TableView(); table.setEditable(true); TableColumn firstName = new TableColumn("First Name"); TableColumn lastName = new TableColumn("Last Name"); TableColumn age = new TableColumn("Age"); TableColumn national = new TableColumn("Nationality"); firstName.setCellFactory(TextFieldTableCell.forTableColumn()); lastName.setCellFactory(TextFieldTableCell.forTableColumn()); age.setCellFactory(TextFieldTableCell.forTableColumn()); national.setCellFactory(TextFieldTableCell.forTableColumn()); table.getColumns().add(firstName); table.getColumns().add(lastName); table.getColumns().add(age); table.getColumns().add(national); table.getItems().addAll(FNAME, LNAME, AGE, NATIONAL); pane.getChildren().add(table); Scene scene = new Scene(pane, 275, 250); primaryStage.setTitle("JavaFX TableView"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }


_____________________________________________

Dark Hers

https://darkhers.blogspot.com

YouTube

https://youtube.com/@darkhers

Instagram

https://instagram.com/darkhers

Facebook

https://www.facebook.com/darkhers

TikTok

https://www.tiktok.com/@darkhers

Pinterest

https://www.pinterest.co.uk/darkhers

Twitter

https://twitter.com/Dark_Hers

Comments

Popular Posts