我尝试定期在JavaFX应用程序后台线程中运行,这会修改一些GUI属性.
我想我知道如何使用Task和Service类,javafx.concurrent并且无法弄清楚如何在不使用Thread#sleep()方法的情况下运行这样的周期性任务.如果我可以使用一些Executor来自Executors制造方法(Executors.newSingleThreadScheduledExecutor())会很好
我试图Runnable每5秒运行一次,重启javafx.concurrent.Service但它会立即挂起,service.restart甚至service.getState()被调用.
所以最后我使用Executors.newSingleThreadScheduledExecutor(),它Runnable每隔5秒发射一次并使用以下命令Runnable运行另一个Runnable:
Platform.runLater(new Runnable() {
//here i can modify GUI properties
}
Run Code Online (Sandbox Code Playgroud)
它看起来非常讨厌:(有没有更好的方法来使用Task或Service类?
我是 Java 和 OOP 新手,并且陷入了向 tableview 列添加图像的困境。代码似乎有效,我可以看到学生的姓名正确,但图像未显示在列中。我收到此错误并且无法理解如何使其工作:
javafx.scene.control.cell.PropertyValueFactory getCellDataReflectively
WARNING: Can not retrieve property 'picture' in PropertyValueFactory: javafx.scene.control.cell.PropertyValueFactory@5b0da50f with provided class type: class model.StudentModel
java.lang.IllegalStateException: Cannot read from unreadable property picture
Run Code Online (Sandbox Code Playgroud)
学生型号:
package model;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.image.ImageView;
import java.util.ArrayList;
import java.util.List;
public class StudentModel {
private ImageView picture;
private String name;
private SubjectModel major;
private SubjectModel minor;
private String accountPassword;
public String getAccountPassword()
{
return accountPassword;
}
public List<LectureModel> lectureModelList = new ArrayList<>();
public StudentModel(String name, SubjectModel …Run Code Online (Sandbox Code Playgroud)