}
public ContextMenu intiContextmenu()
{
final ContextMenu contextMenu = new ContextMenu();
contextMenu.setOnShowing(
new EventHandler<WindowEvent>()
{
@Override
public void handle(WindowEvent e)
{
System.out.println("showing");
}
}
);
contextMenu.setOnShown(new EventHandler<WindowEvent>()
{
@Override
public void handle(WindowEvent e)
{
System.out.println("shown");
}
});
MenuItem item1 = new MenuItem("About");
item1.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
System.out.println("About");
}
});
MenuItem item2 = new MenuItem("Preferences");
item2.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
System.out.println("Preferences");
}
});
MenuItem item3 = new MenuItem("Delete row");
item3.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
System.out.println("Delete row");
Person p = table.getSelectionModel().getSelectedItem();
if(p!=null) {
data.remove(p);
}
}
});
contextMenu.getItems().addAll(item1, item2, item3);
return contextMenu;
}