0

im trying to add some text to a textfield, but when i click the button nothing happens , why is this happening?

MainWindowController.java

@FXML
public static TextField konsumatoriPunetField = new TextField();

@FXML
private void initialize()
{
    FXMLLoader loader5 = new FXMLLoader();
    loader5.setLocation(getClass().getResource("ZgjedhKonsumatorinFXML.fxml"));
    BorderPane border5 = new BorderPane();
    border5 = loader5.load();
    Scene scene5 = new Scene(border5);
    zgjedhkonsumatorinstage.setScene(scene5);
    zgjedhkonsumatorinstage.setTitle("Pit Stop");
    zgjedhkonsumatorinstage.initModality(Modality.WINDOW_MODAL);
    zgjedhkonsumatorinstage.initOwner(MainFXMLController.mainFXMLStage);
}

@FXML
public void zgjedhKonsumatorin()
{
    zgjedhkonsumatorinstage.showAndWait();
}

MainWindowFXML.fxml

<TextField fx:id="konsumatoriPunetField" editable="false" onMouseClicked="#zgjedhKonsumatorin" promptText="Kliko per te zgjedhur" GridPane.columnIndex="1" GridPane.rowIndex="1" />

ZgjedhKonsumatorinController.java

@FXML
public void zgjedhKonsumatorin()
{
    MainWindowController.zgjedhkonsumatorinstage.close();
    MainWindowController.konsumatoriPunetField.setText("ertani");

}

ZgjedhKonsumatorinFXML.fxml

<Button mnemonicParsing="false" onAction="#zgjedhKonsumatorin" prefWidth="150.0" text="Zgjedh Konsumatorin" />
Ertan Hasani
  • 797
  • 1
  • 18
  • 37
  • I cant fix it by that answer. – Ertan Hasani Nov 14 '16 at 11:18
  • Why not? It is exactly the problem: you made the text field static. If you can't fix it by making the text field non-static and using the techniques linked in that question, post a question with your attempt to do that. Fields that are static **will not be injected by the `FXMLLoader`**. Don't keep posting the same question. – James_D Nov 15 '16 at 00:26

0 Answers0