亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

瀏覽:71日期: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文檔中所述,這種情況下的屬性將不是“活動的”:換言之,如果值發生更改,表將不會自動更新。此外,如果您想使表可編輯,則在沒有進行顯式連接以調用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());

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

解決方法

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

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
相關文章:
主站蜘蛛池模板: 久热99这里只有精品视频6 | 手机在线1024 | 被黑人操视频 | 久久综合久久美利坚合众国 | 国产成+人+综合+亚洲不卡 | 日韩久久精品视频 | 黑人巨大进入美女深处的视频 | 免费观看的毛片 | 日韩三级小视频 | 在线观看黄色小视频 | 玖玖色视频 | 香蕉在线精品视频在线观看2 | 中文字幕日韩哦哦哦 | 国产精品免费播放 | 香蕉人精品视频多人免费永久视频 | 色极影院| 女视频www女中国 | 国产精品亚洲精品爽爽 | 国产精品乱码免费一区二区 | 91久久九九精品国产综合 | 国产一区二区不卡视频 | 九九九九精品视频在线播放 | 国产精品亚洲精品日韩已方 | 国产99热久久这里有精品999 | 一级毛片免费观看久 | 在线观看亚洲专区 | 久久精品免费一区二区三区 | 亚洲协和影视 | 亚洲国产日韩女人aaaaaa毛片在线 | 久久91精品国产91久久户 | 亚洲第一区香蕉_国产a | 成人在线观看国产 | 欧美大尺度交性视频 | 真实国产乱子伦精品一区二区三区 | 九九亚洲 | 99久久久精品免费观看国产 | 久久夜色精品国产尤物 | 亚洲欧美日韩一区二区 | 九九精品免费 | 99久久免费午夜国产精品 | 精品国产一区二区三区成人 |