i have given right id in my fxml file but code does't work and no error too.i want to get input all in text and at add button pressed have to fill that data into tableview.Input is text,radio button and checkbox that convetred into string.and at selection of row have to delete that row on remove button click.
public class CashDrawerController implements Initializable
{
@FXML TextField UnitText;
@FXML CheckBox NCCheck;
@FXML TextField CurrencyText;
@FXML RadioButton BillRadio;
@FXML RadioButton CoinRadio;
String select="";
String NC="N";
@FXML TableView<Person> table;
@FXML TableColumn<Person,String> unitcol ;
@FXML TableColumn<Person,String> valuecol ;
@FXML TableColumn<Person,String> typecol ;
@FXML TableColumn<Person,String> nccol ;
private finalObservableList<Person>data=FXCollections.observableArrayList(
new Person("Jacob", "Smith","[email protected]","sadfdsf"),
new Person("Isabella", "Johnson", "[email protected]","sdfsdaf"),
new Person("Ethan", "Williams", "[email protected]","adsfdsf"),
new Person("Emma", "Jones", "[email protected]","dsfsad"),
new Person("Michael", "Brown", "[email protected]","sdfsafd")
);
@FXML
private void handleRemoveButtonAction(ActionEvent ev){
}
@FXML
private void handleAddButtonAction(ActionEvent eve){
if(BillRadio.isSelected()){
select="Bill";
}
if(CoinRadio.isSelected()){
select="Coin";
}
if(NCCheck.isSelected()){
NC="Y";
}
data.add(new Person(
UnitText.getText(),
CurrencyText.getText(),
select,NC));
UnitText.clear();
CurrencyText.clear();
Person obj=new Person("name1","val1","type","nc1");
obj.setUnitName("name2");
obj.setValue("val2");
obj.setType("type2");
obj.setNC("nc2");
unitcol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person,String>("UnitName"));
valuecol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person,String>("Value"));
typecol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person,String>("Type"));
nccol.setCellValueFactory(newjavafx.scene.control.cell.PropertyValueFactory<Person,String>("NC"));
}
@Override
public void initialize(URL url, ResourceBundle rb) {
}
public static class Person {
private final SimpleStringProperty UnitName;
private final SimpleStringProperty Value;
private final SimpleStringProperty Type;
private final SimpleStringProperty NC;
private Person(String uName, String val, String type,String nc) {
this.UnitName = new SimpleStringProperty(uName);
this.Value = new SimpleStringProperty(val);
this.Type = new SimpleStringProperty(type);
this.NC = new SimpleStringProperty(nc);
}
public String getUnitName() {
return UnitName.get();
}
public void setUnitName(String uName) {
UnitName.set(uName);
}
public String getValue() {
return Value.get();
}
public void setValue(String val) {
Value.set(val);
}
public String getType() {
return Type.get();
}
public void setType(String type) {
Type.set(type);
}
public String getNC(){
return NC.get();
}
public void setNC(String nc){
NC.set(nc);
}
}
}
You dont need to set cell factory on each click, can put all
setCellValueFactory
ininitialize
you also need to set
NS
every time in yourhandleAddButtonAction
i think:And the most importent part, i don't see where you are setting your data to the table: Add this in
initialize
table.setItems(data);