TableView: la dernière ligne devient inaccessible aprés suppression
Bonsoir tout le monde,
comme indique dans le titre, je ne peux pas sélectionner la dernière ligne après suppression d'une ligne.
voici le code de la suppression:
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| @FXML
private void deleteUser(ActionEvent event) {
User u = userTable.getSelectionModel().selectedItemProperty().getValue();
if (u != null) {
em.getTransaction().begin();
em.remove(u);
data.remove(u);
em.getTransaction().commit();
}
} |
ChangeListener:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| private final ChangeListener<User> userListener = (value, oldV, newV) -> {
if (oldV != null) {
name.textProperty().unbindBidirectional(oldV.nameProperty());
mail.textProperty().unbindBidirectional(oldV.emailProperty());
birthdayPicker.valueProperty().unbindBidirectional(oldV.birthdayProperty());
}
if (newV != null) {
name.textProperty().bindBidirectional(newV.nameProperty());
mail.textProperty().bindBidirectional(newV.emailProperty());
birthdayPicker.valueProperty().bindBidirectional(newV.birthdayProperty());
}
}; |
voici la classe User:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| @Entity
@Table(name = "USER")
@NamedQueries({
@NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
@NamedQuery(name = "User.findByName", query = "SELECT u FROM User u WHERE u.name = :name"),
@NamedQuery(name = "User.findByEmail", query = "SELECT u FROM User u WHERE u.email = :email")})
public class User {
private static final long serialVersionUID = 1L;
private final StringProperty name = new SimpleStringProperty();
private final StringProperty email = new SimpleStringProperty();
private final ObjectProperty<LocalDate> birthday = new SimpleObjectProperty<>();
public StringProperty nameProperty() {
return name;
}
@Id
@Basic(optional = false)
@Column(name = "NAME")
public String getName() {
return name.get();
}
public void setName(String name) {
this.name.set(name);
}
public StringProperty emailProperty() {
return email;
}
@Column(name = "EMAIL")
public String getEmail() {
return email.get();
}
public void setEmail(String email) {
this.email.set(email);
}
public ObjectProperty<LocalDate> birthdayProperty(){
return birthday;
}
@Column(name = "BIRTHDAY")
@Temporal(TemporalType.DATE)
public LocalDate getBirthday() {
return birthday.get();
}
public void setBirthday(LocalDate birthday){
this.birthday.set(birthday);
}
} |
ce comportement me parait très bizarre!! pour quoi? je m'explique:
le problème apparait seulement quand la TableView doit contenir exactement 6 lignes. si je supprime la quatrième ou cinquième ligne, la dernière ligne (forcement la cinquième) devient inaccessible(non sélectionnable). dés que je fais une autre suppression la ligne qui n'était pas inaccessible devient accessible!!.