Question

I am trying to add a context menu to a circle element using JavaFX 2 FXML. Adding the menu in code works perfectly, adding it in FXML does not work.

FXML:

 <Circle fx:id="connectionStatusCircle" fill="#ff6666" layoutX="14.0" layoutY="11.0" radius="8.0" stroke="BLACK" strokeType="INSIDE">
      <contextMenu>
          <ContextMenu>
              <items>
                  <MenuItem mnemonicParsing="false" text="Unspecified Action" />
              </items>
          </ContextMenu>
      </contextMenu>
</Circle>

The thrown exception is:

Caused by: javafx.fxml.LoadException: Invalid property.

Any ideas?

Was it helpful?

Solution

for Circle it is not possible to add Context Menu in FXMl at designing because its not defined in the property of circle so you have to it pragmatically .

try this-----

cm  =new ContextMenu();
    MenuItem a = new MenuItem("A");
    MenuItem b = new MenuItem("B");
    MenuItem c = new MenuItem("C");
    cm.getItems().addAll(a,b,c);
    circle.setOnMouseClicked(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent t) {
            if(t.getButton().toString().equals("SECONDARY"))
           cm.show(circle,t.getScreenX(),t.getSceneY());
        }
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top