色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

我的表格視圖中的表格單元為空。JavaFX + Scenebuilder

瀏覽:97日期:2024-04-25 16:53:32
如何解決我的表格視圖中的表格單元為空。JavaFX + Scenebuilder?

您的get方法名稱錯誤。根據PropertyValueFactory文檔,如果傳入屬性名稱“xyz”,則屬性值工廠將首??先xyzproperty()在表行中查找屬于該對象的方法。如果找不到,將重新尋找一種稱為getXyz()(仔細查看大寫字母)的方法,然后將結果包裝在中ReadOnlyObjectWrapper。

因此,以下方法將起作用:

package application;import javafx.beans.property.SimpleIntegerProperty;import javafx.beans.property.SimpleStringProperty;public class Table { private final SimpleIntegerProperty bPlayerID; private final SimpleStringProperty bLeague; private final SimpleStringProperty bName; public Table(int cPlayerID, String cLeague, String cName) {this.bPlayerID = new SimpleIntegerProperty(cPlayerID);this.bLeague = new SimpleStringProperty(cLeague);this.bName = new SimpleStringProperty(cName); } public int getBPlayerID() {return bPlayerID.get(); } public void setBPlayerID(int v) {bPlayerID.set(v); } public String getBLeague() {return bLeague.get(); } public void setBLeague(String v) {bLeague.set(v); } public String getBName() {return bName.get(); } public void setBName(String v) {bName.set(v); }}

但是,如PropertyValueFactory文檔中所述,這種情況下的屬性將不是“活動的”:換言之,如果值發(fā)生更改,表將不會自動更新。此外,如果您想使表可編輯,則在沒有進行顯式連接以調用set方法的情況下,它不會更新屬性。

最好使用“ 屬性和綁定”教程中的大綱定義表模型:

package application;import javafx.beans.property.SimpleIntegerProperty;import javafx.beans.property.IntegerProperty;import javafx.beans.property.SimpleStringProperty;import javafx.beans.property.StringProperty;public class Table { private final IntegerProperty bPlayerID; private final StringProperty bLeague; private final StringProperty bName; public Table(int cPlayerID, String cLeague, String cName) {this.bPlayerID = new SimpleIntegerProperty(cPlayerID);this.bLeague = new SimpleStringProperty(cLeague);this.bName = new SimpleStringProperty(cName); } public int getBPlayerID() {return bPlayerID.get(); } public void setBPlayerID(int v) {bPlayerID.set(v); } public IntegerProperty bPlayerIDproperty() {return bPlayerID ; } public String getBLeague() {return bLeague.get(); } public void setBLeague(String v) {bLeague.set(v); } public StringProperty bLeagueproperty() {return bLeague ; } public String getBName() {return bName.get(); } public void setBName(String v) {bName.set(v); } public StringProperty bNameproperty() {return bName ; }}

如果這樣做,則(在Java 8中)可以使用以下單元格值工廠,而不是PropertyValueFactory:

aPlayerID.setCellValueFactory(cellData -> cellData.getValue().bPlayerIDproperty());

這將允許編譯器捕獲任何錯誤,而不僅僅是在運行時靜默失敗。

解決方法

我試圖讓表單元格在創(chuàng)建新行時顯示字符串。但是所有行都是空的。有人知道我在做什么錯嗎?這是主要的類:包應用程序;

import javafx.application.Application;import javafx.fxml.FXMLLoader;import javafx.scene.Cursor;import javafx.scene.Parent;import javafx.scene.Scene;import javafx.stage.Stage;public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ Parent root = FXMLLoader.load(getClass().getResource('/fxml/BasketCase_GUI_0.3.fxml')); Scene scene = new Scene(root,1110,740); scene.getStylesheets().add(getClass().getResource('application.css').toExternalForm()); primaryStage.setResizable(false); primaryStage.setScene(scene); primaryStage.setTitle('Basket Case_Beta'); primaryStage.show(); scene.setCursor(Cursor.DEFAULT);} public static void main(String[] args) throws Exception {launch(args); }}

這是正常的并且可以正常工作,所以我認為您不必為此擔心。

這是控制器類。我認為問題可能出在哪里。

package application;import java.net.URL;import java.util.ResourceBundle;import javafx.beans.property.SimpleStringProperty;import javafx.collections.FXCollections;import javafx.collections.ObservableList;import javafx.event.ActionEvent;import javafx.fxml.FXML;import javafx.fxml.Initializable;import javafx.scene.control.TableColumn;import javafx.scene.control.TableView;import javafx.scene.control.cell.PropertyValueFactory;public class MainController implements Initializable { @FXML TableView<Table> TableID; @FXML TableColumn<Table,Integer> aPlayerID; @FXML TableColumn<Table,String> aLeague; @FXML TableColumn<Table,String> aName; private int aNumber = 1; SimpleStringProperty str = new SimpleStringProperty(); public MainController() {str.set('Hello'); } final ObservableList<Table> data = FXCollections.observableArrayList( new Table(aNumber++,'hehe','hoho'),new Table(aNumber++,'hoho') ); public void buttonClick(ActionEvent event) {data.add(new Table(aNumber++,'hoho'));TableID.getColumns().addAll(aPlayerID,aLeague,aName); } @Override public void initialize(URL arg0,ResourceBundle arg1) {aPlayerID.setCellValueFactory( new PropertyValueFactory<Table,Integer>('bPlayerID'));aLeague.setCellValueFactory( new PropertyValueFactory<Table,String>('bLeague'));aName.setCellValueFactory( new PropertyValueFactory<Table,String>('bName'));TableID.setItems(data); }}

這也是tableviewer所需的表類

package application;import javafx.beans.property.SimpleIntegerProperty;import javafx.beans.property.SimpleStringProperty;public class Table { private final SimpleIntegerProperty bPlayerID; private final SimpleStringProperty bLeague; private final SimpleStringProperty bName; public Table(int cPlayerID,String cLeague,String cName) {this.bPlayerID = new SimpleIntegerProperty(cPlayerID);this.bLeague = new SimpleStringProperty(cLeague);this.bName = new SimpleStringProperty(cName); } public int getbPlayerID() {return bPlayerID.get(); } public void setbPlayerID(int v) {bPlayerID.set(v); } public String getbLeague() {return bLeague.get(); } public void setbLeague(String v) {bLeague.set(v); } public String getbName() {return bName.get(); } public void setbName(String v) {bName.set(v); }}

你們知道什么地方可能出錯,或者建議我如何只添加tableviewer,使其代碼仍可與SceneBuilder中的其余fxml文件一起使用?

標簽: java
相關文章:
主站蜘蛛池模板: 视频三区精品中文字幕 | 国产精品秒播无毒不卡 | 成人高清无遮挡免费视频软件 | 九一精品| 亚州国产 | 在线观看免费黄色网址 | 日本成人不卡视频 | 欧美怡红院免费全视频 | 国产在线极品 | 美女一级毛片视频 | 日韩免费一区二区三区在线 | 国产一级性生活 | 性久久久久久久久久 | 真人一级毛片免费观看视频 | 午夜欧美日韩在线视频播放 | 成人18视频在线 | 欧美xx一片 | 欧美日韩国产va另类 | 免费人成在线观看视频不卡 | 香港三级日本三级人妇网站 | 99久久视频 | 久久成人免费 | 久草免费福利视频 | 99久久免费精品 | 亚洲精品久久精品h成人 | 九九久久精品国产 | 一级一黄在线观看视频免费 | 一区二区三区欧美日韩国产 | 久久久久国产精品免费看 | 97免费在线 | 亚洲国产成人超福利久久精品 | 欧美成人 一区二区三区 | 7m视频精品凹凸在线播放 | 亚洲精彩视频在线观看 | 亚洲 欧美 激情 另类 自拍 | 男人透女人超爽视频免费 | 久草久在线 | 久久视频免费观看 | 国产三a级日本三级日产三级 | 精品亚洲一区二区三区 | 免费黄色美女视频 |