Change the content value of a javafx tableview line

Asked

Viewed 287 times

0

Next, I’m using hsqldb to do a college job, and I need to change the content of a tableview view view

inserir a descrição da imagem aqui

In this case, in the columns Team name, you would need instead of code, the team name

The seat is mounted like this:

inserir a descrição da imagem aqui

and the controller is like this:

@FXML private Button btnSalvar;
  @FXML private TableView<Partida> tabela;
  @FXML private TableColumn<Partida, String> clmTime1;
  @FXML private TableColumn<Partida, Integer> clmPlacar1;
  @FXML private TableColumn<String, String> clmX;
  @FXML private TableColumn<Partida, Integer> clmPlacar2;
  @FXML private TableColumn<Partida, String> clmTime2;

  public void initialize(URL location, ResourceBundle resources) {

      clmTime1.setCellValueFactory(new PropertyValueFactory<>("cod_time1"));
      clmPlacar1.setCellValueFactory(new PropertyValueFactory<>("gol_time1"));
      clmX.setCellValueFactory(new PropertyValueFactory<>(""));
      clmPlacar2.setCellValueFactory(new PropertyValueFactory<>("gol_time2"));
      clmTime2.setCellValueFactory(new PropertyValueFactory<>("cod_time2"));
      refreshTable();         
  }

  @FXML
  private void refreshTable() {
        ArrayList<Partida> listaPartida = new partidaDAO().listarPartidas();
        ObservableList<Partida> observableList = FXCollections.observableArrayList(listaPartida);
        tabela.setItems(observableList);        
    }

how could this change take place?

  • Hello, enter the code in the question and not a print.

  • Oops, I changed it here

1 answer

0


You can perform a Join between tables to show names instead of codes and pass this change to your code. Let’s assume your table is this way (Sqlfiddle), then select below produces the result:

select t1.`nome`, `gols_time1`, t2.`nome`, `gols_time2` from partida
inner join `time` t1 on (`time1` = t1.`idtime`)
inner join `time` t2 on (`time2` = t2.`idtime`)

Flamengo 0 Vasco 0

Your problem is more your database query than a Javafx problem, because your code is correct. (To receive a string type name)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.