赞
踩
首先要配置FXML,安装JavaFX Scene Builder ,这里可以参考网上教程
FXML使用的基本步骤(基本)
扩展
然后选择tableview 创建表格,在设计完表格之后,选择view中show sample controller skeleton 复制代码,粘贴到xxxControll文件中
- public class userSelectControll {
- @FXML
- private TextField selectbook;
- @FXML
- private Button commit;
- @FXML
- private Button backbtn;
- @FXML
- private TableColumn<book, String > pressCol;
- @FXML
- private TableColumn<book, Integer> idCol;
- @FXML
- private TableColumn<book, String > authorCol;
- @FXML
- private TableColumn<book, String > nameCol;
- @FXML
- private TableView<book> myTable;
- @FXML
- private TableColumn<book, Integer> borrowCol;
- @FXML
- private TableColumn<book, Float> priceCol;
- @FXML
- void commitClick(ActionEvent event) {
-
- String sb=selectbook.getText();
- System.out.println(sb);
- System.out.println("查找如下:");
- if (bookDao.selectAllStudent(sb).isEmpty()==false){
- ArrayList<book> list = bookDao.selectAllStudent(sb);
- idCol.setCellValueFactory(new PropertyValueFactory<>("bid"));
- nameCol.setCellValueFactory(new PropertyValueFactory<>("bname"));
- authorCol.setCellValueFactory(new PropertyValueFactory<>("author"));
- pressCol.setCellValueFactory(new PropertyValueFactory<>("publish"));
- priceCol.setCellValueFactory(new PropertyValueFactory<>("bprice"));
- borrowCol.setCellValueFactory(new PropertyValueFactory<>("isborrow"));
- myTable.getItems().clear();//清空表格里面所有数据
- myTable.getItems().addAll(list);
- userMenuApplication open1=new userMenuApplication();
- try {
- } catch (Exception e) {
- e.printStackTrace();
- }
- }else{
- Alert alert = new Alert(Alert.AlertType.INFORMATION, "未查找到此书!");
- alert.showAndWait();
- try {
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- @FXML
- void backbtnClick(ActionEvent event) throws Exception {
- userMenuApplication open = new userMenuApplication();
- open.start(new Stage());
- userSelectApplication.st.hide();//选择后开启一个新的窗体的同时,关闭当前窗体
- }
- }
-
-
-

在图二设计视图的使用,每个表格对应的id和fxid 都要设置,并且要一致,Contrller class 要选择自己创建的xxxcontrller
- @FXML
- private TableColumn<book, Integer> borrowCol;
-
- @FXML
- private TableView<book> myTable;
-
- idCol.setCellValueFactory(new PropertyValueFactory<>("bid"));
-
- myTable.getItems().clear();//清空表格里面所有数据
- myTable.getItems().addAll(list);
-
book 基础包的封装,返回的是book类型的集合
这样就可以通过fxml展示一个表格,结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。