1

I create toolbar like this:

Toolbar with MenuButton(s)

using MenuButton with popup (by this example: Button with popup showed below).


FXML (View)

<?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>

Coresponding Controller

package sample;

import javafx.fxml.FXML;
import javafx.scene.control.MenuButton;
import javafx.scene.input.MouseEvent;

public class Controller {
    private MenuButton actualShowed = null;

    @FXML
    private void buttonEntered(MouseEvent event) {
        if (actualShowed != null)
            actualShowed.hide();

        MenuButton actualButton = (MenuButton)event.getSource();
        actualButton.show();
        actualShowed = actualButton;
    }

    @FXML
    private void buttonClicked(MouseEvent event) {}

    @FXML
    private void buttonExited(MouseEvent event) {
        //((MenuButton)event.getSource()).hide();
    }
}

I would like to show popup panel after mouseEntered and hide after mouseExited the panel or the corresponding button.

Actually works correctly only show panel after mouseEntered event.

Problems are:

  • panel hides after click on button or after click on panel (or its part),
  • panel doesn't hide after mouseExited panel or corresponding button.
Community
  • 1
  • 1
user3102393
  • 87
  • 2
  • 9

0 Answers0