gpt4 book ai didi

JavaFX隐藏id列

转载 作者:行者123 更新时间:2023-11-30 07:21:27 26 4
gpt4 key购买 nike

我的问题是,我需要用户无法从 TableView 中的数据库中知道“id_column”,但我需要它能够从所选行中删除/更新汽车。

示例:

  • User is selecting some row with car in tableview and push "delete_button". Now i have problem because i need id to delete that car from database (here can be more than one car with same attributes) but user can't be allow to see that column.
id || name || cost
1 car1 34.30
2 car1 34.30
3 car2 34.30
4 car3 55.00

name || cost
car1 34.30
car1 34.30
car2 34.30
car3 55.00

有什么想法吗?

编辑

import java.net.URL;
import java.util.ResourceBundle;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

public class HomeController implements Initializable {
private Student studentToDelete = null;

@FXML private TableView<Student> table;
@FXML private TableColumn<Student, Integer> id;
@FXML private TableColumn<Student, String> name;
@FXML private TableColumn<Student, String> surname;
@FXML private TableColumn<Student, Integer> age;


public ObservableList<Student> list = FXCollections.observableArrayList(
new Student(1,"dupa","nazwisko",32),
new Student(2,"afuj","nazwisko",23)
);
DataBase db = new DataBase();
public ObservableList<Student> lista = FXCollections.observableArrayList(db.getAllStudents());



@Override
public void initialize(URL location, ResourceBundle resources) {
id.setCellValueFactory(new PropertyValueFactory<Student, Integer>("id"));
name.setCellValueFactory(new PropertyValueFactory<Student, String>("name"));
surname.setCellValueFactory(new PropertyValueFactory<Student, String>("surname"));
age.setCellValueFactory(new PropertyValueFactory<Student, Integer>("age"));
table.setItems(lista);

}

@FXML
private void initialize() {

// Listen for selection changes
table.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Student>() {



@Override
public void changed(ObservableValue<? extends Student> observable, Student oldValue, Student newValue) {

studentToDelete = newValue;
}

});
}

@FXML
private void deleteClicked () // or whatever your onAction handler is
{
if (studentToDelete != null)
{
System.out.println("test");
}
}

}

现在应该是这样的?

最佳答案

supp.setOnAction(e-> {

table.getColums.remove(tableColumn);

});

关于JavaFX隐藏id列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37494191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com