gpt4 book ai didi

java - javafx 中 TableColumn 的 setCellValueFactory 不会为一个值输入文本,但会添加空格

转载 作者:行者123 更新时间:2023-12-01 13:22:10 26 4
gpt4 key购买 nike

所以我遇到的主要问题是尝试设置 columnUUID.setCellValueFactory(
new PropertyValueFactory<Person,String>("different")
);
时它不会填充 columnPlayer.setCellValueFactory(
new PropertyValueFactory<Person,String>("player")
);
作品。如果我将两者都设置为“player”的值,则会使用这些值填充两个表。如果我将两种方法设置为“不同”,它只会添加空白文本。在两个类中将“不同”更改为不同的值不会执行任何操作。

package com.sandislandserv.rourke750.Gui;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Map;

import com.sandislandserv.rourke750.BetterAssociations;
import com.sandislandserv.rourke750.database.BaseValues;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;

公共(public)类 GuiController {

@FXML private TextField username;
@FXML private TextField domain;
@FXML private PasswordField password;
@FXML private AnchorPane pane;
@FXML private Button login;
@FXML private TableView<Person> listofPlayers;
@FXML private Label badLogin;
@FXML private TableColumn<Person, String> columnUUID;
@FXML private TableColumn<Person, String> columnPlayer;

private ObservableList<Person> data = FXCollections.observableArrayList();
public GuiController() {
}

public AnchorPane getPane(){
return pane;
}

@FXML
public void Login(){
data.clear();
badLogin.setVisible(false);
System.out.print(username.getText());
System.out.print(password.getText());
String players = getPlayers(username.getText().toString(), password.getText().toString());
String[] player = players.split(" ");
for (int x = 0; x < player.length; x=x+2){
System.out.println(player[x] + " " + player[x+1]); // makes sure that both values are populated [for debugging]
data.add(new Person(player[x], player[x+1]));
}
columnUUID.setCellValueFactory(
new PropertyValueFactory<Person,String>("different")
);
columnPlayer.setCellValueFactory(
new PropertyValueFactory<Person,String>("player")
);
listofPlayers.getItems().setAll(data);
}

public String getPlayers(String username, String password){
StringBuilder builder = new StringBuilder();
try {
@SuppressWarnings("resource")
Socket socket = new Socket(domain.getText().toString(), 25549);
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.println(username + " " + password);
if (input.readLine().equals("BAD")) {
badLogin.setVisible(true);
return null;
}
out.println("Get All Player Info");
String line;
while ((line = input.readLine()) != null){
if (line.equals("END")) break;
builder.append(line + " ");
}
out.println("END");
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return builder.toString();
}

}`

`包 com.sandislandserv.rourke750.Gui;

导入javafx.beans.property.SimpleStringProperty;导入 javafx.beans.property.StringProperty;

公共(public)类人{

private StringProperty different;
private StringProperty player;

public Person(String player, String playerid) {
this.player = new SimpleStringProperty(player);
different = new SimpleStringProperty(playerid);
}

public String getPlayer(){
return player.get();
}

public String getUUID(){
return different.get();
}

}

`

最佳答案

将您的 getUUID 方法重命名为 getDifferent 它应该可以工作。更好的是,提供一个返回 different differentProperty 方法。

PropertyValueFactory 根据您提供的名称查找方法。更多信息在javadoc .

关于java - javafx 中 TableColumn 的 setCellValueFactory 不会为一个值输入文本,但会添加空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21962015/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com