如何在锚定窗格的按钮上添加工具提示?

问题描述 投票:0回答:1

我在锚定窗格中有一些按钮,想知道如何将工具提示添加到按钮。这是我的fxml文件

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.MenuButton?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.ScrollBar?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane id="AnchorPane" prefHeight="800.0" prefWidth="1855.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="calibre.FXMLDocumentController">
    <children>
        <Button fx:id="button" layoutX="6.0" layoutY="7.0" onAction="#handleAddBookButtonAction" prefHeight="32.0" prefWidth="200.0" text="Add Books" /> 
            <tooltip><Tooltip text="my tooltip" /></tooltip>
        </Button>
        <Label fx:id="label" layoutX="6.0" layoutY="7.0" minHeight="16" minWidth="69" />
      <Button layoutX="274.0" layoutY="7.0" mnemonicParsing="false" onAction="#handleEditMetadataButtonAction" prefHeight="32.0" prefWidth="200.0" stylesheets="@style.css" text="Edit Metadata" />
      <Button layoutX="564.0" layoutY="7.0" mnemonicParsing="false" onAction="#handleFetchNewsButtonAction" prefHeight="32.0" prefWidth="200.0" text="Fetch News" />
      <Button layoutX="839.0" layoutY="7.0" mnemonicParsing="false" onAction="#handleRemoveButtonAction" prefHeight="32.0" prefWidth="200.0" text="Remove" />
      <Button layoutX="1225.0" layoutY="9.0" mnemonicParsing="false" onAction="#handleLibraryButtonAction" prefHeight="32.0" prefWidth="200.0" text="Library" />
      <MenuButton layoutX="1607.0" layoutY="11.0" minWidth="200.0" mnemonicParsing="false" text="MenuButton" textFill="#eeeeee">
        <items>
          <MenuItem mnemonicParsing="false" text="Action 1" />
          <MenuItem mnemonicParsing="false" text="Action 2" />
        </items>
      </MenuButton>
      <ImageView fitHeight="564.0" fitWidth="358.0" layoutX="747.0" layoutY="166.0" pickOnBounds="true" preserveRatio="true">
         <image>
            <Image url="@Books/1.png" />
         </image></ImageView>
      <ScrollBar layoutX="54.0" layoutY="773.0" prefHeight="18.0" prefWidth="1781.0" />
      <ImageView fitHeight="564.0" fitWidth="358.0" layoutX="149.0" layoutY="180.0" pickOnBounds="true" preserveRatio="true">
         <image>
            <Image url="@Books/4.jpg" />
         </image>
      </ImageView>
      <ImageView fitHeight="564.0" fitWidth="358.0" layoutX="1325.0" layoutY="159.0" pickOnBounds="true" preserveRatio="true">
         <image>
            <Image url="@Books/3.png" />
         </image>
      </ImageView>
      <Button layoutX="382.0" layoutY="722.0" mnemonicParsing="false" onAction="#handleReadHemingwayButtonAction" onDragOver="#handleReadBookHoverTip" text="Read" />
      <Button layoutX="985.0" layoutY="722.0" mnemonicParsing="false" onAction="#handleReadGentlemanButtonAction" text="Read" />
      <Button layoutX="1580.0" layoutY="731.0" mnemonicParsing="false" onAction="#handleReadFlowersButtonAction" text="Read" />
    </children>
</AnchorPane>

但是它表示工具提示在Anchorpanes中不存在。这是否意味着我需要从an鱼鱼更换,如果可以的话,我有什么选择。我正在Netbeans中进行此操作。

温馨的问候

java button javafx netbeans tooltip
1个回答
0
投票

如果您有控制器类,则可以从初始化方法中的此方法获取工具提示

yourBtnId.setTooltip(new Tooltip("Add Customer"));

如果使用XML编辑

<Button>
     <tooltip><Tooltip  textAlignment="CENTER" text="HELLO" /></tooltip>
</Button>
© www.soinside.com 2019 - 2024. All rights reserved.