Je suis nouveau à Java et Java FX et Scene Builder. J'ai mis un TabPane dans un BorderPane et essaye maintenant de peupler le TableView que j'ai mis dans le TabPane avec des valeurs. J'ai 2 classes, la classe de joueur et la classe de PlayerList. va juste remplir les éléments de quelque part plus tard, comme ceci:Comment peupler les cellules TableView - utilisé Scene Builder
public class PlayerList {
ObservableList<Player> playerList;
public PlayerList() {
getPlayersFromServer();
}
private getPlayersFromServer() {
this.playerList = FXCollections.observableArrayList(
new Player("freakyy85","Owner");
new Player("Ky3ak","Owner");
);
}
}
Maintenant, comment puis-je remplir les lignes tableView en utilisant quelque chose comme ceci:
nickColumn.setCellValueFactory(
new PropertyValueFactory<Player,String>("nick")
);
groupColumn.setCellValueFactory(
new PropertyValueFactory<Player,String>("group")
);
j'ai demandé comment faire et où faire qu'en utilisant le constructeur de scène parce que, je n'ai pas eu un ensemble fx: id. Maintenant, j'ai un ensemble, mais je ne sais tout simplement pas comment le faire.
classe ressemble joueur peut ceci:
public class Player {
private SimpleStringProperty nick;
private SimpleStringProperty group;
public Player (String nick, String group) {
this.nick = new SimpleStringProperty(nick);
this.group = new SimpleStringProperty(group);
}
public String getNick() {
return nick.get();
}
public String getGroup() {
return group.get();
}
public void setNick (String nick) {
this.nick.set(nick);
}
public void setGroup (String group) {
this.group.set(group);
}
}
FXMLDocumentController.java:
package uctool;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.input.InputMethodEvent;
public class FXMLDocumentController {
@FXML
private ResourceBundle resources;
@FXML
private URL location;
@FXML
private TableColumn<?, ?> nickColumn;
@FXML
private TableColumn<?, ?> groupColumn;
@FXML
void handleTextChanged(InputMethodEvent event) {
}
@FXML
void initialize() {
assert nickColumn != null : "fx:id=\"nickColumn\" was not injected: check your FXML file 'FXMLDocument.fxml'.";
assert groupColumn != null : "fx:id=\"groupColumn\" was not injected: check your FXML file 'FXMLDocument.fxml'.";
}
}
FXMLDocument.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" stylesheets="@../../resources/UCTool.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="uctool.FXMLDocumentController">
<center>
<TabPane prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER">
<tabs>
<Tab closable="false" text="Players">
<content>
<TableView editable="true" onInputMethodTextChanged="#handleTextChanged" prefHeight="200.0" prefWidth="200.0">
<columns>
<TableColumn fx:id="nickColumn" prefWidth="75.0" text="Nickname" />
<TableColumn fx:id="groupColumn" prefWidth="75.0" text="Group" />
</columns>
<padding>
<Insets bottom="3.0" left="5.0" right="5.0" top="3.0" />
</padding>
</TableView>
</content>
</Tab>
<Tab closable="false" text="Untitled Tab 2" />
</tabs>
</TabPane>
</center>
</BorderPane>
Pas vraiment sûr si vous demandez où placer les appels à 'setCellValueFactory (...)' ou si vous demandez quelque chose d'autre ...? –