1

I have an FXML file that I'm using to allow user input when requested. Right now I just put it in a new stage and do Stage.show(). I would like to not have it appear in a new window and behave more like a ContextMenu.

Looking at ContextMenu class it doesn't appear that I can set the content based off an FXML file. Is there a way to do this either with ContextMenu or Popup or some other class I am unaware of?

fabian
  • 80,457
  • 12
  • 86
  • 114
Chrispresso
  • 3,660
  • 2
  • 19
  • 31

2 Answers2

6

Although that library is quite nice, I wanted something simple that didn't require 3rd party downloads. I came up with this:

Popup popup = new Popup();
CustomController controller = new CustomController();
FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlfile));
loader.setController(controller);
popup.getContent().add((Parent)loader.load());

The problem was I didn't realize that a Parent could be considered a Node for the method Popup#getContent#add

Chrispresso
  • 3,660
  • 2
  • 19
  • 31
0

ControlsFX has a PopOver control you might like. That PopOver can use any Node for its content, so you can simply create a popover, load a node from FXML and set the content of the popover to that node.

Steven Van Impe
  • 1,153
  • 8
  • 15