Shop
Anmelden
MindFusion

Q: How can I display context menu for diagram elements when they are clicked with right mouse button?

A: Implement DiagramListener.nodeClicked (or linkClicked for links) and show a JMenuPopup, for example:

public void nodeClicked(NodeEvent e)
{
	final DiagramNode node = e.getNode();
	if (e.getMouseButton() == MouseEvent.BUTTON3)
	{
		JPopupMenu menu = new JPopupMenu();
		menu.add("Delete").addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent actionEvent)
			{
				diagram.getNodes().remove(node);
			}
		});
		Point p = diagramView.docToDevice(e.getMousePosition());
		menu.show(diagramView, p.x, p.y);
	}
};

Copyright © 2001-2024 MindFusion LLC. Alle Rechte vorbehalten.
Nutzungsbedingungen - Kontakt