JavaFX表是';t显示数据

JavaFX表是';t显示数据,java,javafx,Java,Javafx,我直接从另一个源代码中获取了这段代码,并证明它最初是有效的,但是当将它放入我自己的EclipseIDE中时,表头会显示出来,但表中的数据不会显示出来。我在其他表示例中遇到了这个问题,其中表数据缺失。我很确定添加到表中的各个对象都是正确生成和添加的,所以我不确定是哪里出了问题。代码如下: package application; import javafx.application.Application; import javafx.collections.FXCollections; impo

我直接从另一个源代码中获取了这段代码,并证明它最初是有效的,但是当将它放入我自己的EclipseIDE中时,表头会显示出来,但表中的数据不会显示出来。我在其他表示例中遇到了这个问题,其中表数据缺失。我很确定添加到表中的各个对象都是正确生成和添加的,所以我不确定是哪里出了问题。代码如下:

package application;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class TableViewSampleMain extends Application {

  @Override
  public void start(Stage stage) {

      TableView<UserAccount> table = new TableView<UserAccount>();

      // Create column UserName (Data type of String).
      TableColumn<UserAccount, String> userNameCol //
              = new TableColumn<UserAccount, String>("User Name");



    // Create column Email (Data type of String).
      TableColumn<UserAccount, String> emailCol//
              = new TableColumn<UserAccount, String>("Email");

      // Create column FullName (Data type of String).
      TableColumn<UserAccount, String> fullNameCol//
              = new TableColumn<UserAccount, String>("Full Name");

      // Create 2 sub column for FullName.
      TableColumn<UserAccount, String> firstNameCol//
              = new TableColumn<UserAccount, String>("First Name");

      TableColumn<UserAccount, String> lastNameCol //
              = new TableColumn<UserAccount, String>("Last Name");

      // Add sub columns to the FullName
      fullNameCol.getColumns().addAll(firstNameCol, lastNameCol);

      // Active Column
      TableColumn<UserAccount, Boolean> activeCol//
              = new TableColumn<UserAccount, Boolean>("Active");

      // Defines how to fill data for each cell.
      // Get value from property of UserAccount. .
      userNameCol.setCellValueFactory(new PropertyValueFactory<>("userName"));
      emailCol.setCellValueFactory(new PropertyValueFactory<>("email"));
      firstNameCol.setCellValueFactory(new PropertyValueFactory<>("firstName"));
      lastNameCol.setCellValueFactory(new PropertyValueFactory<>("lastName"));
      activeCol.setCellValueFactory(new PropertyValueFactory<>("active"));

      // Set Sort type for userName column
      userNameCol.setSortType(TableColumn.SortType.DESCENDING);
      lastNameCol.setSortable(false);

      // Display row data
      ObservableList<UserAccount> list = getUserList();
      table.setItems(list);

      table.getColumns().addAll(userNameCol, emailCol, fullNameCol, activeCol);

      StackPane root = new StackPane();
      root.setPadding(new Insets(5));
      root.getChildren().add(table);

      stage.setTitle("TableView (o7planning.org)");

      Scene scene = new Scene(root, 450, 300);
      stage.setScene(scene);
      stage.show();
  }

  private ObservableList<UserAccount> getUserList() {

      UserAccount user1 = new UserAccount(1L, "smith", "smith@gmail.com", //
              "Susan", "Smith", true);
      UserAccount user2 = new UserAccount(2L, "mcneil", "mcneil@gmail.com", //
              "Anne", "McNeil", true);
      UserAccount user3 = new UserAccount(3L, "white", "white@gmail.com", //
              "Kenvin", "White", false);

      ObservableList<UserAccount> list = FXCollections.observableArrayList(user1, user2, user3);
      return list;
  }

  public static void main(String[] args) {
      launch(args);
  }
}

我复制并粘贴了你的代码,表格已经填好了。你的问题似乎存在于其他地方。这很令人困惑,如果可能的话,也许我有一个有缺陷的JavaFX版本。如果你在其他示例中遇到同样的问题,可能是你的Java版本不是最新的。请确保您运行的是最新的jdk。它不太可能是您的Java版本。这是相当基本的功能,已经稳定了很长时间。更有可能的是,您没有保存、编译或部署某些内容。尝试清理和重建项目,看看是否修复了它。刚刚验证(现在我回到我的计算机上)这对我也有效,代码与发布的完全相同。
package application;

public class UserAccount {

   private Long id;
   private String userName;
   private String email;
   private String firstName;
   private String lastName;
   private boolean active;

   public UserAccount(Long id, String userName, String email, //
           String firstName, String lastName, boolean active) {
       this.id = id;
       this.userName = userName;
       this.email = email;
       this.firstName = firstName;
       this.lastName = lastName;
       this.active = active;
   }

   public Long getId() {
       return id;
   }

   public void setId(Long id) {
       this.id = id;
   }

   public String getUserName() {
       return userName;
   }

   public void setUserName(String userName) {
       this.userName = userName;
   }

   public String getEmail() {
       return email;
   }

   public void setEmail(String email) {
       this.email = email;
   }

   public String getFirstName() {
       return firstName;
   }

   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }

   public String getLastName() {
       return lastName;
   }

   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

   public boolean isActive() {
       return active;
   }

   public void setActive(boolean active) {
       this.active = active;
   }

}