J'ai un problème avec la désactivation des lignes dans un TableView. J'ai un TableView qui contient trois colonnes. Une colonne de nom, une colonne de valeur et une colonne de case à cocher. Si l'utilisateur sélectionne une case à cocher, toutes les lignes doivent être désactivées avec la même valeur que la valeur de la ligne sélectionnée. J'ai essayé d'utiliser le framework ReactFX2 pour créer une liaison entre une propriété désactivée et une cellule, mais cela n'a pas fonctionné. Y at-il un moyen facile de gérer mon problème. Voici mon code:JavaFX, désactiver une ligne complète dans TableView
trafficvolume.class
package ExternalRessources;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableBooleanValue;
public class TrafficVolume {
private SimpleStringProperty name;
private SimpleStringProperty flightLVL;
private BooleanProperty check;
private BooleanProperty disabled;
public TrafficVolume(String name, String flightLVL)
{
this.name = new SimpleStringProperty(name);
this.flightLVL = new SimpleStringProperty(flightLVL);
this.check = new SimpleBooleanProperty(false);
this.disabled = new SimpleBooleanProperty(false);
}
public String getName() {
return name.get();
}
public String getFlightLVL() {
return flightLVL.get();
}
public Boolean getCheck() {
return check.get();
}
public BooleanProperty checkedProperty()
{
return check;
}
public void setCheck(Boolean checked)
{
this.check.set(checked);
}
public BooleanProperty disabledProperty()
{
return disabled;
}
public Boolean getDisabled() {
return disabled.get();
}
}
controller.class
package GUI;
import java.io.IOException;
import java.util.ArrayList;
import javafx.beans.value.ObservableValue;
import ExternalRessources.TrafficVolume;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TablePosition;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.CheckBoxTableCell;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.util.Callback;
public class TVIDSelectionPanelController {
@FXML
private Button BACKBUTTON;
@FXML
private Button TEST;
@FXML
private MenuItem MENUITEMSETTINGS;
@FXML
private MenuBar MENUBAR;
@FXML
private GridPane GRIDPANETVID;
@FXML
private TableView<TrafficVolume> TABLETVID;
@FXML
private TableColumn<TrafficVolume, String> TABLECOLTVID;
@FXML
private TableColumn<TrafficVolume, String> TABLECOLFLIGHTLVL;
@FXML
private TableColumn<TrafficVolume, CheckBox> TABLECOLCHECKBOX;
@FXML
private AnchorPane TABLEPANE;
private ExchangeController exchange;
public ObservableList<TrafficVolume> list = FXCollections.observableArrayList();
@FXML
private void handleBACKBUTTON(ActionEvent event) throws IOException
{
}
public void init(ExchangeController ex)
{
this.exchange =ex;
}
@FXML
public void initalize() throws IOException
{
this.ChooseData();
}
@FXML
private void ChooseData()
{
String EBG = exchange.getSelectedEBG();
switch(EBG)
{
case "Central":
{
this.createTable(exchange.getCentralTVID());
break;
}
case "West":
{
this.createTable(exchange.getWestTVID());
break;
}
case "East":
{
this.createTable(exchange.getEastTVID());
break;
}
case "North":
{
this.createTable(exchange.getNorthTVID());
break;
}
case "South":
{
this.createTable(exchange.getSouthTVID());
break;
}
}
}
private void createTable(ArrayList<ArrayList<String>> ListTVID)
{
for(int i=0;i<ListTVID.size();i++)
{
list.add(new TrafficVolume(ListTVID.get(i).get(0),ListTVID.get(i).get(1)));
}
TableColumn<TrafficVolume, String> TVIDs = new TableColumn<TrafficVolume, String>("TV-ID");
TableColumn<TrafficVolume, String> FLVL = new TableColumn<TrafficVolume, String>("Flight Level");
TableColumn<TrafficVolume, Boolean> checkedCol = new TableColumn<TrafficVolume, Boolean>("Active");
TABLETVID.setItems(list);
TABLETVID.getColumns().addAll(TVIDs,FLVL,checkedCol);
TVIDs.setCellValueFactory(new PropertyValueFactory<TrafficVolume, String>("name"));
FLVL.setCellValueFactory(new PropertyValueFactory<TrafficVolume, String>("flightLVL"));
checkedCol.setCellValueFactory(new PropertyValueFactory<TrafficVolume, Boolean>("check"));
checkedCol.setCellFactory(CheckBoxTableCell.forTableColumn(checkedCol));
checkedCol.setEditable(true);
TABLETVID.setEditable(true);
checkedCol.setCellFactory(CheckBoxTableCell.forTableColumn(new Callback<Integer, ObservableValue<Boolean>>()
{
@Override
public ObservableValue<Boolean> call(Integer param)
{
return list.get(param).checkedProperty();
}
}));
for (TrafficVolume trafficVolume : list) {
trafficVolume.checkedProperty().addListener((obs, wasChecked,isNowChecked) -> {
System.out.println("Checked property for " + trafficVolume.getName() +
" changed from "+wasChecked + " to " + isNowChecked);
});
}
}
//Switch the Scene
@FXML
private void handleSettings(ActionEvent event) throws IOException
{
exchange.setTVIDSelectionPanelScene(MENUBAR.getParent().getScene());
exchange.setTVIDSelectionPanelStage((Stage) MENUBAR.getParent().getScene().getWindow());
exchange.setLastScene(exchange.getTVIDSelectionPanelScene());
exchange.setLastStage(exchange.getTVIDSelectionPanelStage());
exchange.initalizeStageOptions(event, MENUBAR);
}
}
Je veux désactiver toutes les lignes qui ont la même flightlvl comme celle sélectionnée. Exemple
name lvl checked
FFM14 100-300 x
FFM15 100-250
FFM24 300-400
FFM34 400-500
ffm15 doit être désactivé car le lvl fait partie du lvl sélectionné. Merci pour votre aide !!
Commencez [ici] (http://stackoverflow.com/questions/28671132/javafx-checkboxtablecell-get-actionevent-when-user-check-a-checkbox). – Sedrick
le rappel avec case à cocher fonctionne, je parle de désactiver une ligne comme "gris" – Sirox