问题是在表格中显示数据(tableview)
加载数据。 2行,我可以在表格中单击它们。但为什么他们没有显示我不明白。 提前谢谢你
这是我的控制器类。
function clickHandler() {
$('body').css('background-color', 'red');
}
和Main:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" onclick="clickHandler()" value="Click me!" />
模特人
package sample;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import sample.model.Person;
import java.util.ArrayList;
public class Controller {
public ObservableList<Person> observableList;
@FXML
private TableView<Person> table = new TableView<>();
@FXML
private TableColumn<Person, String> name;
@FXML
private TableColumn<Person, String> surname;
@FXML
private TableColumn<Person, String> position;
@FXML
private TableColumn<Person, String> city;
@FXML
private TableColumn<Person, String> street;
@FXML
private TableColumn<Person, Integer> homenumber;
@FXML
private TableColumn<Person, String> birthday;
@FXML
private TableColumn<Person, Integer> salary;
private Main mainApp;
public void setMainApp(Main mainApp) {
this.mainApp = mainApp;
// Добавление в таблицу данных из наблюдаемого списка
table.setItems(getObservableList());
}
public void initTable(){
observableList = getObservableList();
table.setItems(observableList);
name = new TableColumn<Person,String>("Имя");
name.setCellValueFactory(new PropertyValueFactory<>("name"));
surname = new TableColumn<Person,String>("Фамилия");
surname.setCellValueFactory(new PropertyValueFactory<>("surName"));
position = new TableColumn<Person,String>("Должность");
position.setCellValueFactory(new PropertyValueFactory<>("position"));
city = new TableColumn<Person,String>("Город");
city.setCellValueFactory(new PropertyValueFactory<>("city"));
street = new TableColumn<Person,String>("Город");
street.setCellValueFactory(new PropertyValueFactory<>("street"));
homenumber = new TableColumn<Person,Integer>("Дом");
homenumber.setCellValueFactory(new PropertyValueFactory<>("homeNumber"));
birthday = new TableColumn<Person,String>("День рождения");
birthday.setCellValueFactory(new PropertyValueFactory<>("birthday"));
salary = new TableColumn<Person,Integer>("Зарплата");
salary.setCellValueFactory(new PropertyValueFactory<>("salary"));
// table.getColumns().setAll(name, surname, position, city, street, homenumber, birthday, salary);
}
public ObservableList<Person> getObservableList(){
ArrayList<Person> people = new ArrayList<>();
people.add(new Person(1, "33", "33", "33", "33", "33", 6, "33", 7));
people.add(new Person(2, "33", "33", "33", "33", "33", 6, "33", 7));
ObservableList<Person> data = FXCollections.observableArrayList(people);
return data;
}
}