将列名更改为其他时,TableView提供错误

我正在用javaFX编写程序,我创建了tableView,我想将列名更改为其他名称,但是它给我错误,这是我无法识别的原因.这是我的申请表
将列名更改为其他时,TableView提供错误

我创建计时器,进入计时器我尝试更改表的列名,但不成功,这是我的代码

 timer=new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run()
            {
                cnt ++;
                if(cnt % 3 == 0)
                {
                    Vaqt.setText("VAQT");
                    Reys.setText("REYS");
                    Mashrut.setText("MARSHRUT");
                    Status.setText("STATUS");
                }
                else if(cnt % 3 == 1)
                {
                    Vaqt.setText("TIME");
                    Reys.setText("REYS");
                    Mashrut.setText("MARSHRUT");
                    Status.setText("STATUS");
                }
                else if(cnt % 3 == 2)
                {
                    Vaqt.setText("Время");
                    Reys.setText("Рейс");
                    Mashrut.setText("Маршрут");
                    Status.setText("Статус");
                }
                System.out.println(cnt);
                ImageView imageView1 = new ImageView("img/uzairways_logo.jpg");
                ImageView imageView2 = new ImageView("img/uzairways_logo.jpg");
                list =new ArrayList<TableData>();
                list.add(new TableData("12:10", imageView1, "HY 615", "Москва", "прибил в 12:15"));
                list.add(new TableData("14:30", imageView2, "HY 52", "Ташкент", "по расписанию"));
                list.add(new TableData("12:10", imageView1, "HY 615", "Москва", "прибил в 12:15"));
                list.add(new TableData("14:30", imageView2, "HY 52", "Ташкент", "по расписанию"));
                tableView.getItems().clear();
                tableView.getItems().addAll(list);
                System.out.println("Va va");
            }
        },new Date(),1000);

但这给了我以下错误

nged(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:143)
    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:146)
    at com.sun.javafx.scene.control.skin.TableColumnHeader.handlePropertyChanged(TableColumnHeader.java:339)
    at com.sun.javafx.scene.control.skin.TableColumnHeader.lambda$new$48(TableColumnHeader.java:149)
    at com.sun.javafx.scene.control.skin.TableColumnHeader$$Lambda$202/1706095847.call(Unknown Source)
    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$Generic.fireValueChangedEvent(ExpressionHelper.java:361)
    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:143)
    at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
    at javafx.scene.control.TableColumnBase.setText(TableColumnBase.java:191)
    at controllers.Controller$1.run(Controller.java:50)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
Exception in thread "Timer-0" java.lang.IllegalStateException: Not on FX application thread; currentThread = Timer-0
    at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:204)
    at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:364)
    at javafx.scene.Parent$2.onProposedChange(Parent.java:364)
    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$60(BehaviorSkinBase.java:197)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$$Lambda$162/1632724523.call(Unknown Source)
    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:143)
    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:146)
    at com.sun.javafx.scene.control.skin.TableColumnHeader.handlePropertyChanged(TableColumnHeader.java:339)
    at com.sun.javafx.scene.control.skin.TableColumnHeader.lambda$new$48(TableColumnHeader.java:149)
    at com.sun.javafx.scene.control.skin.TableColumnHeader$$Lambda$202/1706095847.call(Unknown Source)
    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$Generic.fireValueChangedEvent(ExpressionHelper.java:361)
    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:143)
    at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
    at javafx.scene.control.TableColumnBase.setText(TableColumnBase.java:191)
    at controllers.Controller$1.run(Controller.java:51)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)

解决方法:

您可以在JavaFX TimeLine中使用TimeLine而不是Timer最好在javaFX中修改GUI您可以在其中使用动画
https://docs.oracle.com/javase/8/javafx/api/javafx/animation/Timeline.html

上一篇:(四)JavaFx项目留言系统---留言管理


下一篇:如何使用Maven构建可运行的JavaFX应用程序?