Issue
Receive my greetings everyone!I'm new to javafx.For my first project of Javafx ,I want to create a tableview which Tablecolumns changes according to an event.Suppose that first time,My tableview has 4 columns such as (name,age,email,address).After an event,I want to add the tablecolumn profession for my tableview to have now 5 columns (name,age,email,adress,profession).After an other event,I want to remove profession for my tableview to have again 4 tablecolumns.Thank you for your help.Excuse me for my english.
Solution
Your table view has four columns so you already know how to add columns to the table view. Adding another is no different,(unless you originally defined your columns using FXML). Regardless, the addition and removal of columns in code is as demonstrated below.
Create your new column (add appropriate generic type info and initialization code):
final TableColumn fifthColumn = new TableColumn("Alien resistance");
// initialize the column
When you receive an event, add the fifth column:
Button insurrection = new Button("Add"):
insurrection.setOnAction(e ->
tableView.getColumns().add(
fifthColumn
)
);
similarly for the action on a remove button:
Button failedCoup = new Button("Remove"):
failedCoup.setOnAction(e ->
tableView.getColumns().remove(
fifthColumn
)
);
Answered By - jewelsea
Answer Checked By - Timothy Miller (JavaFixing Admin)