我有一个名为“出勤”的课程,我有很多参数,我为每个出勤实例添加了按钮。 我在一个列表中添加了许多“出席”。
在应用程序启动后,我不想在那里看到按钮。他们必须被隐藏。 当用户使用鼠标悬停在一行上时,将出现“更改”按钮。这非常好。在用户之后也隐藏了外翻按钮 没有徘徊。
问题是我想在应用程序启动后隐藏按钮 所以也许你有一些想法,我可以放在“初始化”内部,因为它是第一个在应用程序启动后运行的方法。
以下是图片:
公共班级出勤{
private int studentId;
private Date date;
private String status;
Button changeAttendanceButton;
public Attendance(int studentId, Date date, String status) {
this.studentId = studentId;
this.date = date;
this.status = status;
this.changeAttendanceButton = new Button("Change!!");
}
public Button getChangeAttendanceButton() {
return changeAttendanceButton;
}
public void setChangeAttendanceButton(Button changeAttendanceButton) {
this.changeAttendanceButton = changeAttendanceButton;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public int getStudentId() {
return studentId;
}
public void setStudentId(int studentId) {
this.studentId = studentId;
}
Callback<TableColumn<Attendance, String>, TableCell<Attendance, String>> changeAttendanceCallback
= //
new Callback<TableColumn<Attendance, String>, TableCell<Attendance, String>>() {
@Override
public TableCell call(final TableColumn<Attendance, String> param) {
final TableCell<Attendance, String> cell = new TableCell<Attendance, String>() {
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
setText(null);
} else {
changeAttendanceButton.setOnAction(event -> {
Attendance person = getTableView().getItems().get(getIndex());
});
setGraphic(changeAttendanceButton);
setText(null);
}
}
};
return cell;
}
};
}
public class SelectedStudentControler实现Initializable {
@FXML
private TableColumn<Attendance, Date> dateColumn;
@FXML
private TableColumn<Attendance, String> attendanceColumn;
@FXML
private Label name;
@FXML
private Label month;
@FXML
private Label percentage;
@FXML
private Label takenL;
@FXML
private Label skuppedDay;
@FXML
private TableView<Attendance> studentTable;
@FXML
private TableColumn<Attendance, String> changeAttendanceColumn;
Date currentDate = new Date();
ModelManager manager = new ModelManager();
@Override
public void initialize(URL url, ResourceBundle rb) {
dateColumn.setCellValueFactory(new PropertyValueFactory<>("date"));
attendanceColumn.setCellValueFactory(new PropertyValueFactory<>("status"));
changeAttendanceColumn.setCellValueFactory( new PropertyValueFactory<>("changeAttendanceButton"));
manager.loadAllAttendance();
studentTable.setItems(manager.getAllAttendence());
showChangeAttendanceButton();
}
public void showChangeAttendanceButton() {
studentTable.setRowFactory(tableView -> {
final TableRow<Attendance> row = new TableRow<>();
row.hoverProperty().addListener((observable) -> {
final Attendance attendance = row.getItem();
row.setStyle("-fx-background-color:white;");
for (Attendance att : manager.getAllAttendence()) {
if (row.isHover() && attendance == att) {
att.getChangeAttendanceButton().setVisible(true);
row.setStyle("-fx-background-color:#000;-fx-opacity: 0.7;");
}
else {
att.getChangeAttendanceButton().setVisible(false);
}
}
});
return row;
});
}
我想要实现第一张照片,第三张照片将是相同的。 我会感谢每一个解决方案。