JavaFX的。带弹出面板的工具栏

时间:2016-03-31 12:38:32

标签: java javafx

我创建了这样的工具栏:

Toolbar with MenuButton(s)

使用带弹出窗口的MenuButton(通过此示例:Button with popup showed below)。

FXML(查看)

TextBox

Coresponding 控制器

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

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<VBox fx:controller="sample.Controller" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400" prefWidth="600" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <MenuButton mnemonicParsing="false" popupSide="RIGHT" text="Tool 1" onMouseEntered="#buttonEntered" onMouseClicked="#buttonClicked" onMouseExited="#buttonExited">
        <items>
          <MenuItem mnemonicParsing="false">
               <graphic>
                  <VBox>
                     <children>
                        <Label text="Tool 1, Description" />
                        <CheckBox mnemonicParsing="false" text="Checkbox" />
                        <CheckBox mnemonicParsing="false" text="CheckBox" />
                     </children>
                  </VBox>
               </graphic>
          </MenuItem>
        </items>
      </MenuButton>
      <Separator orientation="VERTICAL" prefHeight="10" />
      <MenuButton mnemonicParsing="false" popupSide="RIGHT" text="Tool 2" onMouseEntered="#buttonEntered" onMouseClicked="#buttonClicked" onMouseExited="#buttonExited">
        <items>
          <MenuItem mnemonicParsing="false">
               <graphic>
                  <VBox>
                     <children>
                        <Label text="Tool 2, Description" />
                     </children>
                  </VBox>
               </graphic>
          </MenuItem>
        </items>
      </MenuButton>
      <Separator orientation="VERTICAL" prefHeight="10" />
      <MenuButton mnemonicParsing="false" popupSide="RIGHT" text="Tool 3" onMouseEntered="#buttonEntered" onMouseClicked="#buttonClicked" onMouseExited="#buttonExited">
        <items>
          <MenuItem mnemonicParsing="false" text="Action 1">
               <graphic>
                  <VBox prefHeight="200.0" prefWidth="200.0" />
               </graphic>
          </MenuItem>
        </items>
      </MenuButton>
   </children>
</VBox>

我想在 mouseEntered 之后显示弹出式面板,并在 mouseExited 面板或相应按钮后隐藏。

实际上只能在 mouseEntered 事件后显示面板。

问题是:

  • 面板隐藏在单击按钮后或单击面板(或其部件)后
  • 面板在mouseExited面板或相应按钮后无法隐藏。

0 个答案:

没有答案