英文:
How to insert an array into a TableView in JavaFx?
问题
public void RPserch(ActionEvent event) throws IOException {
ObservableList<Person> data;
TableColumn remark = new TableColumn("Check");
remark.setMinWidth(40);
TableColumn Purchplan = new TableColumn("PurchplanID");
Purchplan.setMinWidth(100);
TableColumn Producplan = new TableColumn("Producplan");
Producplan.setMinWidth(150);
TableColumn RPID = new TableColumn("RPID");
RPID.setMinWidth(110);
TableColumn itemname = new TableColumn("itemname");
itemname.setMinWidth(100);
TableColumn RPamount = new TableColumn("RPamount");
RPamount.setMinWidth(100);
TableColumn RPdate = new TableColumn("RPdate");
RPdate.setMinWidth(200);
TableColumn RPlocation = new TableColumn("RPlocation");
RPlocation.setMinWidth(100);
TableColumn RPperson = new TableColumn("RPperson");
RPperson.setMinWidth(100);
TableColumn buyer = new TableColumn("buyer ");
buyer.setMinWidth(100);
TableColumn condition = new TableColumn("condition");
condition.setMinWidth(100);
RPTableview.getColumns().addAll(remark, Purchplan, Producplan, RPID, itemname, RPamount, RPdate, RPlocation,RPperson, buyer, condition);
Purchplan.setCellValueFactory(new PropertyValueFactory<Person, String>("PurchplanID"));
Producplan.setCellValueFactory(new PropertyValueFactory<Person, String>("Producplan"));
RPID.setCellValueFactory(new PropertyValueFactory<Person, String>("RPID"));
itemname.setCellValueFactory(new PropertyValueFactory<Person, String>("itemname"));
RPamount.setCellValueFactory(new PropertyValueFactory<Person, String>("RPamount"));
RPdate.setCellValueFactory(new PropertyValueFactory<Person, String>("RPdate"));
RPlocation.setCellValueFactory(new PropertyValueFactory<Person, String>("RPlocation"));
RPperson.setCellValueFactory(new PropertyValueFactory<Person, String>("RPperson"));
buyer.setCellValueFactory(new PropertyValueFactory<Person, String>("buyer"));
condition.setCellValueFactory(new PropertyValueFactory<Person, String>("condition"));
String RPserchf = RPserchfield.getText();
try {
String search = RPserchf + "|" + "1|||";
search = search.trim();
System.out.println(search);
os = cltSocket.getOutputStream();
os.write(search.getBytes());
} catch (Exception e) {
e.printStackTrace();
}
try {
in = cltSocket.getInputStream();
String strRcvMsg = "";
byteBuff = new byte[1024];
int nRcvLen = in.read(byteBuff);
strRcvMsg = new String(byteBuff, 0, nRcvLen, "EUC-KR");
Thread.sleep(500);
System.out.println(strRcvMsg);
String[] testmsg = strRcvMsg.split("&");
TableView<Person> RPTableview = new TableView<Person>();
data = FXCollections.observableArrayList(new Person("", testmsg[0], testmsg[1], testmsg[2], testmsg[3],testmsg[4], testmsg[5], testmsg[6], testmsg[7], testmsg[8], testmsg[9]));
for (int i = 0; i < testmsg.length - 1; i++) {
System.out.println(testmsg[i]);
}
RPTableview.setItems(data);
} catch (Exception e) {
System.out.println("[EXP] Tableview " + e.getLocalizedMessage());
}
}
英文:
I want insert an array into a Table View. I've tried and searched several times, but I can't solve it.
When I press the search button, I want to convert messages from the server to an array using split and put each array in each row of the table view.
public void RPserch(ActionEvent event) throws IOException {
ObservableList<Person> data;
TableColumn remark = new TableColumn("Check");
remark.setMinWidth(40);
TableColumn Purchplan = new TableColumn("PurchplanID");
Purchplan.setMinWidth(100);
TableColumn Producplan = new TableColumn("Producplan");
Producplan.setMinWidth(150);
TableColumn RPID = new TableColumn("RPID");
RPID.setMinWidth(110);
TableColumn itemname = new TableColumn("itemname");
itemname.setMinWidth(100);
TableColumn RPamount = new TableColumn("RPamount");
RPamount.setMinWidth(100);
TableColumn RPdate = new TableColumn("RPdate");
RPdate.setMinWidth(200);
TableColumn RPlocation = new TableColumn("RPlocation");
RPlocation.setMinWidth(100);
TableColumn RPperson = new TableColumn("RPperson");
RPperson.setMinWidth(100);
TableColumn buyer = new TableColumn("buyer ");
buyer.setMinWidth(100);
TableColumn condition = new TableColumn("condition");
condition.setMinWidth(100);
RPTableview.getColumns().addAll(remark, Purchplan, Producplan, RPID, itemname, RPamount, RPdate, RPlocation,RPperson, buyer, condition);
Purchplan.setCellValueFactory(new PropertyValueFactory<Person, String>("PurchplanID"));
Producplan.setCellValueFactory(new PropertyValueFactory<Person, String>("Producplan"));
RPID.setCellValueFactory(new PropertyValueFactory<Person, String>("RPID"));
itemname.setCellValueFactory(new PropertyValueFactory<Person, String>("itemname"));
RPamount.setCellValueFactory(new PropertyValueFactory<Person, String>("RPamount"));
RPdate.setCellValueFactory(new PropertyValueFactory<Person, String>("RPdate"));
RPlocation.setCellValueFactory(new PropertyValueFactory<Person, String>("RPlocation"));
RPperson.setCellValueFactory(new PropertyValueFactory<Person, String>("RPperson"));
buyer.setCellValueFactory(new PropertyValueFactory<Person, String>("buyer"));
condition.setCellValueFactory(new PropertyValueFactory<Person, String>("condition"));
This is the table column setting.
The code that runs when the button is pressed from the bottom. The arrangement is well divided, but the arrangement does not seem to go over to the row of the table view.
String RPserchf = RPserchfield.getText();
try {
String search = RPserchf + "|" + "1|||";
search = search.trim();
System.out.println(search);
os = cltSocket.getOutputStream();
os.write(search.getBytes());
} catch (Exception e) {
e.printStackTrace();
}
try {
in = cltSocket.getInputStream();
String strRcvMsg = "";
byteBuff = new byte[1024];
int nRcvLen = in.read(byteBuff);
strRcvMsg = new String(byteBuff, 0, nRcvLen, "EUC-KR");
Thread.sleep(500);
System.out.println(strRcvMsg);
String[] testmsg = strRcvMsg.split("&");
TableView<Person> RPTableview = new TableView<Person>();
data = FXCollections.observableArrayList(new Person("", testmsg[0], testmsg[1], testmsg[2], testmsg[3],testmsg[4], testmsg[5], testmsg[6], testmsg[7], testmsg[8], testmsg[9]));
for (int i = 0; i < testmsg.length - 1; i++) {
System.out.println(testmsg[i]);
}
RPTableview.setItems(data);
} catch (Exception e) {
System.out.println("[EXP] Tableview " + e.getLocalizedMessage());
}
}
答案1
得分: 0
ObservableList<Person> data = FXCollections.observableArrayList(
new Person("", testmsg[0], testmsg[1], testmsg[2], testmsg[3], testmsg[4], testmsg[5], testmsg[6],
testmsg[7], testmsg[8], testmsg[9]));
remark.setCellValueFactory(cellData -> cellData.getValue().remarkProperty());
Purchplan.setCellValueFactory(cellData -> cellData.getValue().PurchplanProperty());
Producplan.setCellValueFactory(cellData -> cellData.getValue().ProducplanProperty());
RPID.setCellValueFactory(cellData -> cellData.getValue().RPIDProperty());
itemname.setCellValueFactory(cellData -> cellData.getValue().itemnameProperty());
RPamount.setCellValueFactory(cellData -> cellData.getValue().RPamountProperty());
RPdate.setCellValueFactory(cellData -> cellData.getValue().RPdateProperty());
RPlocation.setCellValueFactory(cellData -> cellData.getValue().RPlocationProperty());
RPperson.setCellValueFactory(cellData -> cellData.getValue().RPpersonProperty());
buyer.setCellValueFactory(cellData -> cellData.getValue().buyerProperty());
condition.setCellValueFactory(cellData -> cellData.getValue().conditionProperty());
RPTableview.setItems(data);
英文:
I added a column value to the SceneBulider and let each cell have a value.
ObservableList<Person> data = FXCollections.observableArrayList(
new Person("", testmsg[0], testmsg[1], testmsg[2], testmsg[3], testmsg[4], testmsg[5], testmsg[6],
testmsg[7], testmsg[8], testmsg[9]));
remark.setCellValueFactory(cellData -> cellData.getValue().remarkProperty());
Purchplan.setCellValueFactory(cellData -> cellData.getValue().PurchplanProperty());
Producplan.setCellValueFactory(cellData -> cellData.getValue().ProducplanProperty());
RPID.setCellValueFactory(cellData -> cellData.getValue().RPIDProperty());
itemname.setCellValueFactory(cellData -> cellData.getValue().itemnameProperty());
RPamount.setCellValueFactory(cellData -> cellData.getValue().RPamountProperty());
RPdate.setCellValueFactory(cellData -> cellData.getValue().RPdateProperty());
RPlocation.setCellValueFactory(cellData -> cellData.getValue().RPlocationProperty());
RPperson.setCellValueFactory(cellData -> cellData.getValue().RPpersonProperty());
buyer.setCellValueFactory(cellData -> cellData.getValue().buyerProperty());
condition.setCellValueFactory(cellData -> cellData.getValue().conditionProperty());
RPTableview.setItems(data);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论