samedi 17 octobre 2020

Titled Pane Action

I am trying to create a titled pane (JavaFX library) which will generate and show a random word from my dictionary.txt.

I wrote some lines of code and used SceneBuilder to add these code to the TitledPane.

public void generateAmazingWord() {
    Random randomIndex = new Random();
    int upperbound = virtualDictionary.size();
    int randomWordIndex = randomIndex.nextInt(upperbound);
    String amazingWord = virtualDictionary.get(randomWordIndex);
    amazingWordView.getEngine().loadContent(dictionary.get(amazingWord));
}

Everything is okay, but when I clicked the arrow button to expand or close the pane, the code seemed to run simultaneously. It means: I click the arrow (to open), it shows a random word; click again (to close), it shows a random word too.

I don't want this to happen, can someone please give me a solution?




Aucun commentaire:

Enregistrer un commentaire