0

The code below is supposed to allow the user to type in the details of the new product they're adding into a list (except the Choicebox). Almost all of the code works, with the exception being the method handlePrice(). Whenever the user attempts to type into the priceText TextField, the error "Empty String" is thrown and won't allow the user to type any characters at all. All variables are initialized within the code and PartList is an initialized ObservableList.

//TextFields
@FXML
private TextField partNameText;
@FXML
private TextField brandNameText;
@FXML
private TextField itemIDText;
@FXML
private TextField materialText;
@FXML
private TextField priceText;//
@FXML
private void handlePartType() {
    partType = partTypeChoice.getValue();
}

//
@FXML
private void handlePartName() {
    partName = partNameText.getText();
}

//
@FXML
private void handleBrandName() {
    brandName = brandNameText.getText();
}

//
@FXML
private void handleItemID() {
    itemID = itemIDText.getText();
}

//
@FXML
private void handleMaterial() {
    material = materialText.getText();
}

//
@FXML
private void handlePrice() {
    String priceString = priceText.getText();
    price = Double.parseDouble(priceString);
}

//
@FXML
private void newPart() {
    //
    if((partTypeChoice.getValue().isEmpty() == false)&&(partNameText.getText().isEmpty() == false)) {
        //
        PartList.add(partListIndex, new Part(partType, partName, brandName, itemID, material, price));
        partListIndex++;

        //
        partListTable.setItems(PartList);
    }
    else {
        //Changes the text of the Required labels
        partTypeLabel.setText("*Part Type");
        partNameLabel.setText("*Part Name");

        //Changes the color of the Required Labels
        partTypeLabel.setTextFill(javafx.scene.paint.Color.RED);
        partNameLabel.setTextFill(javafx.scene.paint.Color.RED);

        //Displays the warning
        warningLabel.setVisible(true);
        dismissButton.setVisible(true);
    }
}
fabian
  • 80,457
  • 12
  • 86
  • 114
nimbus_b
  • 3
  • 1
  • *"[the textfield] won't allow the user to type any characters at all"* There is no listener to the `text` property of the field in the code you posted and there is no indication where the `handlePrice` method is called from, We cannot help you with your issue unless you add this info to the question. – fabian Apr 08 '18 at 17:40
  • By the way, don’t use `condition == false`. Use `! condition`. – Holger Apr 09 '18 at 06:39

0 Answers0