我的代码遇到了一些麻烦,涉及对组合框的修改。以下代码是fxml文件的控制器。问题来自尝试设置ComboBox禁用时的第49行。 在fxml文件(combo_destination)中通知了fx:id,但仍然存在空指针异常。
我不知道为什么它不起作用,但我认为这似乎很基本?
package ch.makery.adress.view;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import ch.makery.adress.MainApp;
import ch.makery.adress.util.FileFilterXLSX;
import ch.makery.adress.model.Donnees;
import javax.swing.JFileChooser;
public class MenuOverviewController {
@FXML
private ComboBox combo_periode;
@FXML
private ComboBox combo_destination;
@FXML
private ComboBox combo_type_avion;
@FXML
private ComboBox combo_type_vol;
@FXML
private Button button_param;
@FXML
private Button button_valider;
@FXML
private Button button_search;
@FXML
private TextField text_remplissage;
@FXML
private TextField text_path;
private MainApp mainApp;
/* ------------------------- */
public MenuOverviewController() {
combo_destination.setDisable(true);
}
@FXML
private void initialize() {
}
@FXML
private void handleParametresAvances() {
this.mainApp.showParametresOverview();
}
@FXML
private void handleLancement() {
this.mainApp.showRapport();
}
@FXML
private void handleSearch() {
JFileChooser chooser = new JFileChooser("C:\\Users\\Matth\\Documents\\ACTEMIUM\\Convoyeur de tri");
chooser.setDialogTitle("Sélectionner le fichier source");
chooser.setFileFilter(new FileFilterXLSX());
chooser.showOpenDialog(null);
text_path.setText(chooser.getSelectedFile().getPath());
}
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
}
}
/ * FXML文件* /
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="500.0" prefWidth="350.0" stylesheets="@light.css" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.makery.adress.view.MenuOverviewController">
<children>
<TabPane layoutX="14.0" layoutY="14.0" prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<tabs>
<Tab text="Simulation">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<Label layoutX="-22.0" layoutY="7.0" text="Paramétrage de la simulation" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="20.0">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<ComboBox fx:id="combo_type_vol" layoutX="20.0" layoutY="218.0" prefHeight="29.0" prefWidth="198.0" promptText="Type de vol" AnchorPane.leftAnchor="20.0" />
<ComboBox fx:id="combo_type_avion" layoutX="20.0" layoutY="166.0" prefHeight="29.0" prefWidth="197.0" promptText="Type d'avion" AnchorPane.leftAnchor="20.0" />
<ComboBox fx:id="combo_destination" layoutX="20.0" layoutY="113.0" prefHeight="29.0" prefWidth="196.0" promptText="Destination" AnchorPane.leftAnchor="20.0" />
<ComboBox fx:id="combo_periode" layoutX="20.0" layoutY="60.0" prefHeight="29.0" prefWidth="198.0" promptText="Période de l'année" AnchorPane.leftAnchor="20.0" />
<TextField fx:id="text_remplissage" layoutX="230.0" layoutY="168.0" prefHeight="26.0" prefWidth="108.0" promptText="Remplissage (%)" />
<Button fx:id="button_valider" layoutX="81.0" layoutY="387.0" mnemonicParsing="false" onAction="#handleLancement" prefHeight="32.0" prefWidth="200.0" text="Valider le paramétrage" />
<Button fx:id="button_param" layoutX="20.0" layoutY="267.0" mnemonicParsing="false" onAction="#handleParametresAvances" text="Paramètres avancés" />
</children>
</AnchorPane>
</content>
</Tab>
<Tab text="Importation de données">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<TextField fx:id="text_path" layoutX="15.0" layoutY="58.0" prefHeight="26.0" prefWidth="262.0" promptText="Indiquer le chemin du fichier à importer" />
<Button fx:id="button_search" layoutX="286.0" layoutY="59.0" mnemonicParsing="false" onAction="#handleSearch" text="..." />
<Label layoutX="-37.0" layoutY="10.0" text="Importation d'un fichier source" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="20.0">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
</children></AnchorPane>
</content>
</Tab>
<Tab text="Aide">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</Tab>
</tabs>
</TabPane>
</children>
</AnchorPane>