multithreading - 在非 JavaFX 应用程序线程上创建新的工具提示

标签 multithreading tooltip javafx

有没有办法在不是“JavaFX应用程序线程”的线程中创建javafx.scene.control.Tooltip?

出于性能考虑,我在一个线程中准备了一些视觉元素并将它们保存在内存中。当我需要它们时,我使用应用程序线程来显示它们。但 new Tooltip() 似乎只需要应用程序线程。

最佳答案

is there a way how to create javafx.scene.control.Tooltip in thread which is not "JavaFX Application Thread"?

对于 JavaFX 2.2 - 否。

请参阅此 JavaFX 问题跟踪表:Tooltip of Tab (and other controls) cannot be set of FXApplicationThread .

票证中有一个建议的解决方法来创建 TooltipPlatform.runLater打电话。

package fxthread_25127_wrongthread;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.control.Tooltip;
import javafx.stage.Stage;
/**
 *
 * @author mickf
 */
public class Main extends Application {
    Tooltip tooltip;

    public static void main(String[] args) {
        Application.launch(args);
    }
    @Override public void init() throws Exception {
        Platform.runLater(new Runnable() {
            @Override public void run() {
                tooltip = new Tooltip("Top tip : use runLater()");
            }
        });
        /*
         * this will cause an ISE
         */
        //tooltip = new Tooltip("flip");
    }
    @Override public void start(Stage s) {
        System.exit(0);
    }
} 

来自 javadoc 的 Platform.runLater 如何工作的描述:

Run the specified Runnable on the JavaFX Application Thread at some unspecified time in the future. This method, which may be called from any thread, will post the Runnable to an event queue and then return immediately to the caller. The Runnables are executed in the order they are posted. A runnable passed into the runLater method will be executed before any Runnable passed into a subsequent call to runLater.

关于multithreading - 在非 JavaFX 应用程序线程上创建新的工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13864182/

相关文章:

angular - Primeng pTooltip 循环

java - 为什么将首选大小设置为 Double.POSITIVE_INFINITY 或 Double.MAX_VALUE 在 JavaFX 中不起作用,而 10000 却可以?

android - 提高 OpenCV 性能 Android - 快速对象跟踪

使用 Windows API 比较线程 ID

java - 如何使多个线程中的一个线程运行最长时间(等待队列中的最短时间)?

JavaFX:ImageView 仅显示图像一次

java - ListView.setItems() 如何工作?

java - Executors.newFixedThreadPool 挂起的线程

selenium - 如何使用 Selenium WebDriver 获取鼠标悬停时的工具提示文本

html - 工具提示底部定位