Witam próbuje w java FX zrobić dodanie książki do listy, ale tylko gdy wszystkie dane są wprowadzone. Niestety nie wiem jak to zrobić dla combobox by gdy nie jest wybrane to wskazywało na to ze pole jest puste tak jak to robie z text field tam daje getTest().isEmpty() i już dopóki nic nie wpisze przycisk się nie włączy ale jak to zrobic z combo box to nie mam pojęcia.
*.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.collections.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.collections.FXCollections?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.kel.gui.controller.ControllerWindowsAddBook">
<children>
<GridPane gridLinesVisible="true" layoutX="111.0" prefHeight="300.0" prefWidth="288.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="207.0" minWidth="0.0" prefWidth="140.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="280.0" minWidth="10.0" prefWidth="140.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 minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Subtitle" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font size="14.0" />
</font>
</Label>
<Label text="Name author" GridPane.halignment="CENTER" GridPane.rowIndex="2">
<font>
<Font size="14.0" />
</font>
</Label>
<Label text="Surname author" GridPane.halignment="CENTER" GridPane.rowIndex="3">
<font>
<Font size="14.0" />
</font>
</Label>
<Label text="Type Book" GridPane.halignment="CENTER" GridPane.rowIndex="4">
<font>
<Font size="14.0" />
</font>
</Label>
<Label text="Language" GridPane.halignment="CENTER" GridPane.rowIndex="5">
<font>
<Font size="14.0" />
</font>
</Label>
<Label text="Publisher" GridPane.halignment="CENTER" GridPane.rowIndex="6">
<font>
<Font size="14.0" />
</font>
</Label>
<Label text="Year Published" GridPane.halignment="CENTER" GridPane.rowIndex="7">
<font>
<Font size="14.0" />
</font>
</Label>
<Label text="Title" GridPane.halignment="CENTER">
<font>
<Font size="14.0" />
</font>
</Label>
<TextField fx:id="titleTextField" onKeyReleased="#keyReleasedProperty" prefHeight="25.0" prefWidth="133.0" promptText="Title" GridPane.columnIndex="1" />
<TextField fx:id="subtitleTextField" onKeyReleased="#keyReleasedProperty" prefHeight="25.0" prefWidth="0.0" promptText="Subtitle" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="nameAuthorTextField" onKeyReleased="#keyReleasedProperty" promptText="Name author" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField fx:id="surnameAuthorTextField" onKeyReleased="#keyReleasedProperty" promptText="Surname author" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<TextField fx:id="publisherTextField" onKeyReleased="#keyReleasedProperty" promptText="Publisher" GridPane.columnIndex="1" GridPane.rowIndex="6" />
<TextField fx:id="yearPublishedTextField" onKeyReleased="#keyReleasedProperty" promptText="Year Published" GridPane.columnIndex="1" GridPane.rowIndex="7" />
<ComboBox fx:id="typeBookComboBox" onKeyReleased="#keyReleasedProperty" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="4" >
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="Thriller" />
<String fx:value="Science_fiction_Fantasy" />
<String fx:value="Thriller" />
<String fx:value="Comedy" />
<String fx:value="Science" />
<String fx:value="Biography" />
<String fx:value="Business_Finance_Law" />
<String fx:value="Children" />
<String fx:value="Comics" />
<String fx:value="Computing_Internet" />
<String fx:value="Crime" />
<String fx:value="Education" />
<String fx:value="Food_Drink" />
<String fx:value="Health_Family_Lifestyle" />
<String fx:value="History" />
<String fx:value="Home_Garden" />
<String fx:value="Languages" />
<String fx:value="Mind_Body_Spirit" />
<String fx:value="Music_Stage_Screen" />
<String fx:value="Poetry_Drama_Criticism" />
<String fx:value="Reference" />
<String fx:value="Religion_Spirituality" />
<String fx:value="Romance" />
<String fx:value="School_Books" />
<String fx:value="Society_Politics_Philosophy" />
<String fx:value="Sports_Hobbies_Games" />
<String fx:value="Travel_Holiday" />
<String fx:value="Young_Adult" />
</FXCollections>
</items>
<!--<value>-->
<!--<String fx:value="null" />-->
<!--</value>-->
</ComboBox>
<ComboBox fx:id="languageComboBox" onKeyReleased="#keyReleasedProperty" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="5" />
</children>
</GridPane>
<Button fx:id="buttonAddBook" alignment="CENTER" blendMode="DARKEN" disable="true" layoutX="20.0" layoutY="125.0" mnemonicParsing="false" onAction="#onClickButtonAddBook" text="Add Book" textAlignment="CENTER" />
</children>
</Pane>
controllerWindowsAddBook
package com.kel.gui.controller;
import com.kel.model.Book;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import java.util.HashSet;
import java.util.Set;
public class ControllerWindowsAddBook {
private Set<Book> setBook = new HashSet<Book>();
@FXML
private TextField titleTextField;
@FXML
private TextField subtitleTextField;
@FXML
private TextField nameAuthorTextField;
@FXML
private TextField surnameAuthorTextField;
@FXML
private TextField publisherTextField;
@FXML
private TextField yearPublishedTextField;
@FXML
private ComboBox<String> typeBookComboBox;
@FXML
private Button buttonAddBook;
public Set<Book> onClickButtonAddBook(){
return setBook;
}
public void keyReleasedProperty() {
boolean isDisabled = ( titleTextField.getText().isEmpty() ||
subtitleTextField.getText().isEmpty() ||
nameAuthorTextField.getText().isEmpty() ||
surnameAuthorTextField.getText().isEmpty() ||
publisherTextField.getText().isEmpty() ||
yearPublishedTextField.getText().isEmpty() ||
typeBookComboBox.getItems().isEmpty() ||
titleTextField.toString().trim().isEmpty() ||
subtitleTextField.toString().trim().isEmpty() ||
nameAuthorTextField.toString().trim().isEmpty() ||
surnameAuthorTextField.toString().trim().isEmpty() ||
publisherTextField.toString().trim().isEmpty() ||
yearPublishedTextField.toString().trim().isEmpty());
buttonAddBook.setDisable(isDisabled);
}
}