css - 如何使用 css 自定义工具提示?

标签 css javafx-2 tooltip

我正在使用带有开普勒的 javafx 2 版本,我尝试自定义工具提示但没有成功:

.tooltip{
  -fx-background-color: linear-gradient(blue,lightskyblue);
  -fx-background-radius: 5;
}
.page-corner {
  -fx-shape: " ";
}

它不起作用。你有什么想法吗?

更新:

这里是 mcve :

import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class MainApp extends Application {

  @Override
  public void start(Stage stage) {
    AnchorPane root;
    try {   
        root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
        Scene scene = new Scene(root, 600, 400);
        stage.setTitle("FXML Welcome");
        stage.setScene(scene);
        stage.show();
    } catch (IOException e) {
    // TODO Auto-generated catch block
        e.printStackTrace();
     }  
}


  public static void main(String[] args) {
     Application.launch(MainApp.class, args);
  }
}

示例.fxml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.image.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?> 

<AnchorPane prefHeight="400.0" prefWidth="600.0" stylesheets="MCVE/application.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Sample">
   <children>
      <TextField layoutX="66.0" layoutY="49.0">
         <tooltip>
            <Tooltip text="tooltip message" />
         </tooltip>
      </TextField>
   </children>
</AnchorPane>

Controller :

public class Sample {
//controller    
}

application.css 文件:

 .tooltip{
  -fx-background-color: linear-gradient(blue,lightskyblue);
  -fx-background-radius: 5.0;
}
.page-corner {
  -fx-shape: " ";
}

最佳答案

我认为这是因为 Tooltip 出现在它自己的窗口中(TooltipPopupControl 的子类,它最终是窗口)。因为您已将样式表应用到 AnchorPane,它不会被位于该层次结构之外的 Tooltip 看到。

相反,将样式表添加到 MainApp 类中的 Scene:

    scene.getStylesheets().add(getClass().getResource("/mcve/application.css").toExternalForm());

关于css - 如何使用 css 自定义工具提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25765400/

相关文章:

html - bootstrap 怎么会覆盖我的 css 主体?

HTML 在 div 中对齐一个词

javascript - 使用 HTML 表单的 jQuery 验证修复格式

reflection - 根据数据类信息自动创建 TableView 列

JavaFX 应用程序线程变慢然后卡住

twitter-bootstrap - 将 Bootstrap 的工具提示对齐到元素的左侧?

html - body 后出现额外的边距

twitter-bootstrap - 模式关闭后,如何防止焦点集中在 Bootstrap 模式的切换按钮上?

c# - 如何摆脱 Visual Studio 2010 中烦人的代码提示?

java - 除了 javafx.beans.property 提供的机制之外,我是否应该在非图形用户界面应用程序逻辑中使用其他东西?