Button JavaFX TableView、标签和按钮选择不起作用,外观和表外观被禁用

Button JavaFX TableView、标签和按钮选择不起作用,外观和表外观被禁用,button,javafx,label,tableview,javafx-8,Button,Javafx,Label,Tableview,Javafx 8,这是我在这个伟大社区的第一个问题。我在这个博客上开始了一个JavaFX教程。但是我使用IntelliJ IDEA而不是Eclipse。程序编译成功,但左侧的TableView和右侧的标签看起来都已禁用(字体颜色为灰色而非黑色,鼠标悬停或单击时无法突出显示表格)。所以我的问题是:为什么我不能选择表视图 package com.melkojji.controller; 导入com.melkojji.model.Person; 导入com.melkojji.view.PersonOverviewCo

这是我在这个伟大社区的第一个问题。我在这个博客上开始了一个JavaFX教程。但是我使用IntelliJ IDEA而不是Eclipse。程序编译成功,但左侧的TableView和右侧的标签看起来都已禁用(字体颜色为灰色而非黑色,鼠标悬停或单击时无法突出显示表格)。所以我的问题是:为什么我不能选择表视图

package com.melkojji.controller;
导入com.melkojji.model.Person;
导入com.melkojji.view.PersonOverviewController;
导入javafx.application.application;
导入javafx.collections.FXCollections;
导入javafx.collections.ObservableList;
导入javafx.fxml.fxmloader;
导入javafx.scene.scene;
导入javafx.scene.layout.ancorpane;
导入javafx.scene.layout.BorderPane;
导入javafx.stage.stage;
导入java.io.IOException;
公共类主扩展应用程序{
私人阶段初级阶段;
私有边界布局;
私有ObservableList personData=FXCollections.observableArrayList();
公用干管(){
本.personData.add(新人物(“Mustapha”、“HUSAIN”);
添加(新人物(“Mustapha”、“EL KOJJI”);
}
公共静态void main(字符串[]args){
发射(args);
}
@凌驾
公共无效开始(阶段primaryStage){
this.primaryStage=primaryStage;
本.primaryStage.setTitle(“AdressApp”);
这个。初级阶段。设置最小宽度(615);
这个。初级阶段。设置最小高度(365);
initRootLayout();
showPersonOverview();
}
public void initRootLayout(){
试一试{
//从fxml文件加载根布局。
FXMLLoader=新的FXMLLoader();
setLocation(Main.class.getResource(“../view/RootLayout.fxml”);
rootLayout=(BorderPane)loader.load();
}捕获(IOE异常){
e、 printStackTrace();
}
//显示包含根布局的场景。
场景=新场景(根布局);
初级阶段。场景(场景);
primaryStage.show();
}
public void showPersonOverview(){
试一试{
//装载人员概述。
FXMLLoader=新的FXMLLoader();
setLocation(Main.class.getResource(“../view/PersonOverview.fxml”);
AnchorPane personOverview=(AnchorPane)loader.load();
//将人员概览设置到根布局的中心。
rootLayout.setCenter(personOverview);
//让控制器访问主应用程序。
PersonOverviewController=loader.getController();
控制器setMain(this);
}捕获(IOE异常){
e、 printStackTrace();
}
}
公共阶段getPrimaryStage(){
返回初级阶段;
}
公共观察列表getPersonData(){
返回个人数据;
}
}

package com.melkojji.view;
导入com.melkojji.controller.Main;
导入com.melkojji.model.Person;
导入com.melkojji.util.DateUtil;
导入javafx.fxml.fxml;
导入javafx.scene.control.Label;
导入javafx.scene.control.TableColumn;
导入javafx.scene.control.TableView;
/**
*由melkojji于2017年1月14日创建。
*/
公共类PersonOverview控制器{
@FXML
私有TableView personTableView;
@FXML
private TableColumn personFirstNameTableColumn;
@FXML
私有TableColumn personLastNameTableColumn;
@FXML
自有品牌firstNameLabel;
@FXML
自有品牌lastNameLabel;
@FXML
自有标签路标;
@FXML
私人标签邮递标签;
@FXML
自有品牌cityLabel;
@FXML
自有品牌生日标签;
//对主应用程序的引用。
私人主楼;
/**
*构造器。
*在initialize()方法之前调用构造函数。
*/
公共人员概述控制器(){
}
/**
*初始化控制器类。自动调用此方法
*加载fxml文件后。
*/
@FXML
公共无效初始化(){
//使用这两列初始化person表。
这个.personFirstNameTableColumn.setCellValueFactory(cellData->cellData.getValue().firstNameProperty());
this.personLastNameTableColumn.setCellValueFactory(cellData->cellData.getValue().lastNameProperty());
//清楚个人信息。
showPersonDetails(空);
//侦听选择更改并在更改时显示人员详细信息。
personTableView.getSelectionModel().SelectEditeProperty().addListener(((可观察、旧值、新值)->showPersonDetails(新值));
}
/**
*由主应用程序调用以返回对自身的引用。
*
*@param main
*/
公共无效设置主(主){
this.main=main;
//将可观察列表数据添加到表中。
this.personTableView.setItems(main.getPersonData());
}
/**
*填充所有文本字段以显示有关此人的详细信息。
*如果指定的人员为空,则清除所有文本字段。
*
*@param person为person或null
*/
公开作废showPersonDetails(个人){
if(person!=null){
//使用来自person对象的信息填充标签。
firstnamelab.setText(person.getFirstName());
setText(person.getLastName());
streetLabel.setText(person.getStreet());
postalCodeLabel.setText(Integer.toString(person.getPostalCode());
cityLabel.setText(person.getCity());
birthdayLabel.setText(DateUtil.format(person.getBirthday());
//生日标签。setText(…);
}否则{
//Person为空,请删除所有文本。
firstnamelab.setText(“”);
package com.melkojji.controller;

import com.melkojji.model.Person;
import com.melkojji.view.PersonOverviewController;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

import java.io.IOException;

public class Main extends Application {

    private Stage primaryStage;
    private BorderPane rootLayout;
    private ObservableList<Person> personData = FXCollections.observableArrayList();

    public Main() {
        this.personData.add(new Person("Mustapha", "HUSAIN"));
        this.personData.add(new Person("Mustapha", "EL KOJJI"));
    }

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

    @Override
    public void start(Stage primaryStage) {
        this.primaryStage = primaryStage;
        this.primaryStage.setTitle("AdressApp");
        this.primaryStage.setMinWidth(615);
        this.primaryStage.setMinHeight(365);
        initRootLayout();
        showPersonOverview();
    }

    public void initRootLayout() {
        try {
            // Load root layout from fxml file.
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(Main.class.getResource("../view/RootLayout.fxml"));
            rootLayout = (BorderPane) loader.load();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Show the scene containing the root layout.
        Scene scene = new Scene(rootLayout);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public void showPersonOverview() {
        try {
            // Load person overview.
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(Main.class.getResource("../view/PersonOverview.fxml"));
            AnchorPane personOverview = (AnchorPane) loader.load();
            // Set person overview into the center of root layout.
            rootLayout.setCenter(personOverview);
            // Give the controller access to the main app.
            PersonOverviewController controller = loader.getController();
            controller.setMain(this);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public Stage getPrimaryStage() {
        return primaryStage;
    }

    public ObservableList<Person> getPersonData() {
        return personData;
    }
}
package com.melkojji.view;

import com.melkojji.controller.Main;
import com.melkojji.model.Person;
import com.melkojji.util.DateUtil;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;

/**
 * Created by melkojji on 1/14/2017.
 */
public class PersonOverviewController {
    @FXML
    private TableView<Person> personTableView;
    @FXML
    private TableColumn<Person, String> personFirstNameTableColumn;
    @FXML
    private TableColumn<Person, String> personLastNameTableColumn;
    @FXML
    private Label firstNameLabel;
    @FXML
    private Label lastNameLabel;
    @FXML
    private Label streetLabel;
    @FXML
    private Label postalCodeLabel;
    @FXML
    private Label cityLabel;
    @FXML
    private Label birthdayLabel;
    // Reference to the main application.
    private Main main;

    /**
     * The constructor.
     * The constructor is called before the initialize() method.
     */
    public PersonOverviewController() {
    }

    /**
     * Initializes the controller class. This method is automatically called
     * after the fxml file has been loaded.
     */
    @FXML
    public void initialize() {
        // Initialize the person table with the two columns.
        this.personFirstNameTableColumn.setCellValueFactory(cellData -> cellData.getValue().firstNameProperty());
        this.personLastNameTableColumn.setCellValueFactory(cellData -> cellData.getValue().lastNameProperty());
        // Clear person details.
        showPersonDetails(null);
        // Listen for selection changes and show the person details when changed.
        personTableView.getSelectionModel().selectedItemProperty().addListener(((observable, oldValue, newValue) -> showPersonDetails(newValue)));
    }

    /**
     * Is called by the main application to give a reference back to itself.
     *
     * @param main
     */
    public void setMain(Main main) {
        this.main = main;
        // Add observable list data to the table.
        this.personTableView.setItems(main.getPersonData());
    }

    /**
     * Fills all text fields to show details about the person.
     * If the specified person is null, all text fields are cleared.
     *
     * @param person the person or null
     */
    public void showPersonDetails(Person person) {
        if (person != null) {
            // Fill the labels with info from the person object.
            firstNameLabel.setText(person.getFirstName());
            lastNameLabel.setText(person.getLastName());
            streetLabel.setText(person.getStreet());
            postalCodeLabel.setText(Integer.toString(person.getPostalCode()));
            cityLabel.setText(person.getCity());
            birthdayLabel.setText(DateUtil.format(person.getBirthday()));
            // birthdayLabel.setText(...);
        } else {
            // Person is null, remove all the text.
            firstNameLabel.setText("");
            lastNameLabel.setText("");
            streetLabel.setText("");
            postalCodeLabel.setText("");
            cityLabel.setText("");
            birthdayLabel.setText("");
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.layout.BorderPane?>


<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="325.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
   <top>
      <MenuBar BorderPane.alignment="CENTER">
        <menus>
          <Menu mnemonicParsing="false" text="File">
            <items>
              <MenuItem mnemonicParsing="false" text="Close" />
            </items>
          </Menu>
          <Menu mnemonicParsing="false" text="Edit">
            <items>
              <MenuItem mnemonicParsing="false" text="Delete" />
            </items>
          </Menu>
          <Menu mnemonicParsing="false" text="Help">
            <items>
              <MenuItem mnemonicParsing="false" text="About" />
            </items>
          </Menu>
        </menus>
      </MenuBar>
   </top>
</BorderPane>
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>

<AnchorPane disable="true" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.melkojji.view.PersonOverviewController">
   <children>
      <SplitPane dividerPositions="0.29797979797979796" prefHeight="300.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <items>
          <AnchorPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="160.0" prefWidth="100.0">
               <children>
                  <TableView fx:id="personTableView" editable="true" onSort="#initialize" prefHeight="298.0" prefWidth="175.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                    <columns>
                      <TableColumn fx:id="personFirstNameTableColumn" prefWidth="75.0" text="First name" />
                      <TableColumn fx:id="personLastNameTableColumn" prefWidth="75.0" text="Last name" />
                    </columns>
                     <columnResizePolicy>
                        <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
                     </columnResizePolicy>
                  </TableView>
               </children></AnchorPane>
          <AnchorPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="160.0" prefWidth="100.0">
               <children>
                  <Label layoutX="14.0" layoutY="14.0" text="Person details :" AnchorPane.leftAnchor="5.0" AnchorPane.topAnchor="5.0" />
                  <GridPane AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="30.0">
                    <columnConstraints>
                      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                    </columnConstraints>
                    <rowConstraints>
                      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                    </rowConstraints>
                     <children>
                        <Label text="First name" />
                        <Label text="Last name" GridPane.rowIndex="1" />
                        <Label text="Street" GridPane.rowIndex="2" />
                        <Label text="City" GridPane.rowIndex="3" />
                        <Label text="Postal code" GridPane.rowIndex="4" />
                        <Label text="Birthday" GridPane.rowIndex="5" />
                        <Label fx:id="firstNameLabel" text="Label" GridPane.columnIndex="1" />
                        <Label fx:id="lastNameLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1" />
                        <Label fx:id="streetLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" />
                        <Label fx:id="cityLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" />
                        <Label fx:id="postalCodeLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="4" />
                        <Label fx:id="birthdayLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="5" />
                     </children>
                  </GridPane>
                  <ButtonBar prefHeight="40.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0">
                    <buttons>
                      <Button mnemonicParsing="false" text="New" />
                        <Button mnemonicParsing="false" text="Edit" />
                        <Button mnemonicParsing="false" text="Delete" />
                    </buttons>
                     <padding>
                        <Insets right="5.0" />
                     </padding>
                  </ButtonBar>
               </children></AnchorPane>
        </items>
      </SplitPane>
   </children>
</AnchorPane>
<AnchorPane disable="true" ..>