午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

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

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

您的get方法名稱錯(cuò)誤。根據(jù)PropertyValueFactory文檔,如果傳入屬性名稱“xyz”,則屬性值工廠將首??先xyzproperty()在表行中查找屬于該對(duì)象的方法。如果找不到,將重新尋找一種稱為getXyz()(仔細(xì)查看大寫字母)的方法,然后將結(jié)果包裝在中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文檔中所述,這種情況下的屬性將不是“活動(dòng)的”:換言之,如果值發(fā)生更改,表將不會(huì)自動(dòng)更新。此外,如果您想使表可編輯,則在沒有進(jìn)行顯式連接以調(diào)用set方法的情況下,它不會(huì)更新屬性。

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

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());

這將允許編譯器捕獲任何錯(cuò)誤,而不僅僅是在運(yùn)行時(shí)靜默失敗。

解決方法

我試圖讓表單元格在創(chuàng)建新行時(shí)顯示字符串。但是所有行都是空的。有人知道我在做什么錯(cuò)嗎?這是主要的類:包應(yī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); }}

這是正常的并且可以正常工作,所以我認(rèn)為您不必為此擔(dān)心。

這是控制器類。我認(rèn)為問題可能出在哪里。

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); }}

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

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 色亚洲色图 | 久久国产成人 | 成人一二区 | 免费av播放 | 亚洲人体视频 | 久久久久久久久久免费视频 | 九色视频在线播放 | 97精品一区二区视频在线观看 | 91视频第一页| 激情五月色播 | 亚洲视频欧美 | 岛国片在线免费观看 | 久久午夜国产精品 | 九九99精品| www.久久视频 | 久久成人激情 | 国产又猛又黄又爽 | 热久久最新 | 欧美日韩一区二区在线观看视频 | 在线成人亚洲 | 成人在线毛片 | av青娱乐| 久久字幕| 性视频软件 | 精品国产一区二区三区久久狼黑人 | 欧美色吊丝 | 国内精品999 | 一二三av| 欧美69av | 中文一区二区在线观看 | 在线视频久 | 香蕉视频在线观看免费 | 亚洲天天 | 人人av在线 | 韩国一级黄色录像 | 午夜私人影院在线观看 | 成人观看视频 | 亚洲免费网站 | 都市激情自拍偷拍 | 色婷婷av一区二区三区之e本道 | 欧美专区在线观看 |