Javafx ImageView工具提示样式

时间:2014-09-15 13:55:36

标签: css javafx javafx-8

我已经将全局样式应用于所有工具提示,并且它正常工作,除非工具提示安装到ImageView上。如果我将工具提示添加到ImageView的父级(HBox),则样式是正确的,因此样式表没有被添加就不会有问题。

css样式如下所示:

.tooltip
{
    -fx-border-color: gray;
    -fx-border-radius: 5.0 5.0 5.0 5.0;
    -fx-background-radius: 5.0 5.0 5.0 5.0;
    -fx-background-color:  white;
    -fx-text-fill: black;
    -fx-wrap-text: true;
}

向imageview添加工具提示(样式不起作用):

 Tooltip.install(imageviewFormat, formatTooltip);

将工具提示添加到父级(样式确实有效):

 Tooltip.install(imageviewFormat.getParent(), formatTooltip);

我在这里做了些蠢事,或者ImageView没有从其父级继承css。任何见解都将不胜感激。

更新 以下示例具有此行为,其中style.css包含相同的工具提示样式。

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Tooltip;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class Test extends Application
{
    public static void main(String[] args) throws Exception
    {
        launch(args);
    }

    @Override
    public void start(Stage primarystage) throws Exception
    {
        HBox root = new HBox();
        root.getStylesheets().add(getClass().getResource("style.css").toExternalForm());

        ImageView imageView = new ImageView("http://www.samjarman.co.nz/images/so.png");
        root.getChildren().add(imageView);

        Tooltip.install(imageView, new Tooltip("Tooltip")); // Doesn't work
        // Tooltip.install(imageView.getParent(), new Tooltip("Tooltip")); // Works

        Scene scene = new Scene(root);
        primarystage.setScene(scene);
        primarystage.show();
    }
}

由于

0 个答案:

没有答案