无法从某些方法中修改标签

时间:2017-04-25 19:48:17

标签: netbeans javafx fxml

我有一个我在NetBeans中创建的Java FXML应用程序,到目前为止所有内容都按预期工作,但随着我开始改进所有内容并使其更加用户,我遇到了这个特定代码的问题:

@FXML
private Label differenceResultsLabel;
@FXML
private Label responseTimeResultsLabel;

public boolean checkForResponseTime(double[] responseTimeArray)
{
    int arrayLength = responseTimeArray.length;
    double maxThreshold = Double.parseDouble(maxResponseTime.getText());
    for (int i=0; i < arrayLength ; i++)
    {
        if (responseTimeArray[i] > maxThreshold)
        {
            System.out.println("Response Time beyond threshold!");
            responseTimeResultsLabel.setTextFill(Color.RED);
            responseTimeResultsLabel.setText(Arrays.toString(responseTimeArray));
            return false;
        }
    }
    System.out.println("All response times OK");
    responseTimeResultsLabel.setTextFill(Color.GREEN);
    responseTimeResultsLabel.setText(Arrays.toString(responseTimeArray));
    System.out.println("Hello?");
    return true;
}

请注意,FXMLDocument.fxml文件中的标签已经是fx:id'd。 但是,当我运行程序时,标签不会改变(即使我得到其他行(Hello?和所有响应时间都可以)。

这是输出注意:我删除了一系列SYSTEM.OUTPRINTLN以使其更易于阅读

Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
    Time logged: 14.178
        at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
    2017-04-25T12:35:07.230is above target temp for channel 0
        at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
    2017-04-25T12:35:07.548is above target temp for channel 1
    2017-04-25T12:35:07.884is above target temp for channel 2
    2017-04-25T12:35:08.219is above target temp for channel 3
        at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
    2017-04-25T12:35:07.548is above target temp for channel 4
    2017-04-25T12:35:07.548is above target temp for channel 5
    2017-04-25T12:35:07.884is above target temp for channel 6
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:113)
    2017-04-25T12:35:07.884is above target temp for channel 7
    The updated indexes for initial findings are: [7, 8, 9, 10, 8, 8, 9, 9, 0]
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:108)
    2017-04-25T12:35:16.777is above target temp for channel 0
    2017-04-25T12:35:14.477is above target temp for channel 1
    2017-04-25T12:35:19.092is above target temp for channel 2
    2017-04-25T12:35:19.092is above target temp for channel 3
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:575)
    2017-04-25T12:35:13.488is above target temp for channel 4
    2017-04-25T12:35:13.153is above target temp for channel 5
    2017-04-25T12:35:16.777is above target temp for channel 6
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(LabeledSkinBase.java:204)
    2017-04-25T12:35:14.477is above target temp for channel 7
    The updated indexes for final findings are: [36, 29, 43, 43, 26, 25, 36, 29, 0]
    Channel 1 had a response time of: 9.547
        at com.sun.javafx.scene.control.skin.LabelSkin.handleControlPropertyChanged(LabelSkin.java:49)
    Channel 2 had a response time of: 6.929
    Channel 3 had a response time of: 11.208
    Channel 4 had a response time of: 10.873
    Channel 5 had a response time of: 5.9399999999999995
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase.lambda$registerChangeListener$61(BehaviorSkinBase.java:197)
    Channel 6 had a response time of: 5.605
    Channel 7 had a response time of: 8.893
    Channel 8 had a response time of: 6.593
    The updated response times are: [9.547, 6.929, 11.208, 10.873, 5.9399999999999995, 5.605, 8.893, 6.593]
        at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(MultiplePropertyChangeListenerHandler.java:55)
    Max RT is: 11.208. Min RT is: 5.605
    Percent difference is 0.6665080592398738%. Max percent difference is: 0.5
        at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:89)
        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
        at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
        at javafx.beans.property.StringProperty.setValue(StringProperty.java:65)
        at javafx.scene.control.Labeled.setText(Labeled.java:145)
        at at.qcresponsetime.FXMLDocumentController.doStopTest(FXMLDocumentController.java:297)
        at at.qcresponsetime.FXMLDocumentController.serialEvent(FXMLDocumentController.java:785)
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:772)
        at gnu.io.RXTXPort.eventLoop(Native Method)
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1641)
    Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
        at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
        at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
    Percentage test is: false
        at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
    All response times OK
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:113)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:108)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:575)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(LabeledSkinBase.java:204)
        at com.sun.javafx.scene.control.skin.LabelSkin.handleControlPropertyChanged(LabelSkin.java:49)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase.lambda$registerChangeListener$61(BehaviorSkinBase.java:197)
        at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(MultiplePropertyChangeListenerHandler.java:55)
        at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:89)
        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
        at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
        at javafx.beans.property.StringProperty.setValue(StringProperty.java:65)
        at javafx.scene.control.Labeled.setText(Labeled.java:145)
        at at.qcresponsetime.FXMLDocumentController.doGet8Results(FXMLDocumentController.java:352)
        at at.qcresponsetime.FXMLDocumentController.serialEvent(FXMLDocumentController.java:786)
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:772)
        at gnu.io.RXTXPort.eventLoop(Native Method)
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1641)
    Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
        at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
        at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
        at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:113)
    Response Time test is: true
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:108)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:575)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(LabeledSkinBase.java:204)
        at com.sun.javafx.scene.control.skin.LabelSkin.handleControlPropertyChanged(LabelSkin.java:49)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase.lambda$registerChangeListener$61(BehaviorSkinBase.java:197)
        at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(MultiplePropertyChangeListenerHandler.java:55)
        at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:89)
        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
        at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
        at javafx.beans.property.StringProperty.setValue(StringProperty.java:65)
        at javafx.scene.control.Labeled.setText(Labeled.java:145)
        at at.qcresponsetime.FXMLDocumentController.checkPercentage(FXMLDocumentController.java:460)
        at at.qcresponsetime.FXMLDocumentController.doGet8Results(FXMLDocumentController.java:387)
        at at.qcresponsetime.FXMLDocumentController.serialEvent(FXMLDocumentController.java:786)
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:772)
        at gnu.io.RXTXPort.eventLoop(Native Method)
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1641)
    Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
        at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
        at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
        at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:113)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:108)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:575)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(LabeledSkinBase.java:204)
        at com.sun.javafx.scene.control.skin.LabelSkin.handleControlPropertyChanged(LabelSkin.java:49)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase.lambda$registerChangeListener$61(BehaviorSkinBase.java:197)
        at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(MultiplePropertyChangeListenerHandler.java:55)
        at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:89)
        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
        at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
        at javafx.beans.property.StringProperty.setValue(StringProperty.java:65)
        at javafx.scene.control.Labeled.setText(Labeled.java:145)
        at at.qcresponsetime.FXMLDocumentController.writeRTLabel(FXMLDocumentController.java:291)
        at at.qcresponsetime.FXMLDocumentController.checkForResponseTime(FXMLDocumentController.java:416)
        at at.qcresponsetime.FXMLDocumentController.doGet8Results(FXMLDocumentController.java:389)
        at at.qcresponsetime.FXMLDocumentController.serialEvent(FXMLDocumentController.java:786)
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:772)
        at gnu.io.RXTXPort.eventLoop(Native Method)
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1641)
    Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
        at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
        at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
        at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:113)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:108)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:575)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(LabeledSkinBase.java:204)
        at com.sun.javafx.scene.control.skin.LabelSkin.handleControlPropertyChanged(LabelSkin.java:49)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase.lambda$registerChangeListener$61(BehaviorSkinBase.java:197)
        at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(MultiplePropertyChangeListenerHandler.java:55)
        at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:89)
        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
        at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
        at javafx.beans.property.StringProperty.setValue(StringProperty.java:65)
        at javafx.scene.control.Labeled.setText(Labeled.java:145)
        at at.qcresponsetime.FXMLDocumentController.setFail(FXMLDocumentController.java:563)
        at at.qcresponsetime.FXMLDocumentController.doGet8Results(FXMLDocumentController.java:397)
        at at.qcresponsetime.FXMLDocumentController.serialEvent(FXMLDocumentController.java:786)
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:772)
        at gnu.io.RXTXPort.eventLoop(Native Method)
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1641)
    Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4
        at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
        at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
        at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:113)
        at com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:108)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:575)
        at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(LabeledSkinBase.java:204)
        at com.sun.javafx.scene.control.skin.LabelSkin.handleControlPropertyChanged(LabelSkin.java:49)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase.lambda$registerChangeListener$61(BehaviorSkinBase.java:197)
        at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(MultiplePropertyChangeListenerHandler.java:55)
        at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:89)
        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
        at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
        at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
        at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
        at javafx.beans.property.StringProperty.setValue(StringProperty.java:65)
        at javafx.scene.control.Labeled.setText(Labeled.java:145)
        at at.qcresponsetime.FXMLDocumentController.setFail(FXMLDocumentController.java:564)
        at at.qcresponsetime.FXMLDocumentController.doGet8Results(FXMLDocumentController.java:397)
        at at.qcresponsetime.FXMLDocumentController.serialEvent(FXMLDocumentController.java:786)
        at gnu.io.RXTXPort.sendEvent(RXTXPort.java:772)
        at gnu.io.RXTXPort.eventLoop(Native Method)
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1641)

0 个答案:

没有答案