Java FXML TextArea.setText()停止工作

时间:2017-05-02 20:04:46

标签: java fxml

我正在尝试更新Java FXML程序中的TextArea并遇到一个奇怪的问题。我能够更新指令2次,但在同一更新调用的第三个实例上,文本字段将不会更新。我使用相同的方法调用所有更新,并获得了应该显示在控制台中打印的内容,所以我知道问题是TextArea更新。以下是导致问题的代码:

private void freedomCheck(){        // method for starting out a composition, choosing "mode"
    decisionIndex = 0;
    this.addChord("I");                 //initialize first chord to "I"
    prompt[0] = "Please enter your degree of freedom: 1, 2, 3, or 4."; //display prompt
    prompt[1] = "1: Composes and plays for you";
    prompt[2] = "2: Fill in just notes with chords given to you";
    prompt[3] = "3: Fill in chords and notes, with software giving you options for both";
    prompt[4] = "4: Fill in chords and notes with full independence";
    prompt();                   // get user input (can be changed to button press, etc.

}

private void prompt(){
    String displayString = "";
    for(int i=0;i<5;i++){
        displayString += prompt[i] + "\n";
    }
    setInstructions(displayString);
    System.out.println(displayString);
}

    public void setInstructions(String newString){
    instruction_text.setText(newString);
}

prompt []数组用于快速分隔文本行。代码的这一部分在显示器上正常工作和打印,但稍后当我尝试使用相同的prompt()调用更新它时:

    public void promptNotes(){
    decisionIndex = 4;
    int index;
    if (composition.noteLength() == 0)
        index = composition.getSize() - 1;
    else index = composition.noteLength();
    prompt[0] = "The current chord is " + composition.getChord(index).getName() + "; please pick a note:";//prompt

    Chord temp = composition.getChord(composition.getSize()-1);
    ArrayList<Note> candidates = temp.getOfferedNotes();
    int notesLen = candidates.size();       //length of notes list for current chord

    for(int i = 1; i < 5; i++){
        tempNotes[i] = candidates.get(notesLen - i);
        prompt[i] = (i+1) + ": " + tempNotes[i].getName();
    }
    prompt();
}

正确的输出打印到控制台,但textArea不会更新。

0 个答案:

没有答案