I am using JavaFX and my application has a table and I can add elements to the table but I want to create a context menu that displays on a row when I right click on that row.>
JavaFX 8 (with Lambda):
MenuItem mi1 = new MenuItem("Menu item 1");
mi1.setOnAction((ActionEvent event) -> {
System.out.println("Menu item 1");
Object item = table.getSelectionModel().getSelectedItem();
System.out.println("Selected item: " + item);
});
ContextMenu menu = new ContextMenu();
menu.getItems().add(mi1);
table.setContextMenu(menu);
See also: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ContextMenu.html