# Changing the cursor shape in a popup menu?

**URL:** <https://forum.inductiveautomation.com/t/changing-the-cursor-shape-in-a-popup-menu/106618>\
**Category:** Ignition\
**Tags:** vision, scripting\
**Created:** [May 23, 2025, 8:45am UTC](https://forum.inductiveautomation.com/t/changing-the-cursor-shape-in-a-popup-menu/106618 "2025-05-23T08:45:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henk](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@Henk](https://forum.inductiveautomation.com/u/Henk)\
**Post date:** [May 23, 2025, 8:45am UTC](https://forum.inductiveautomation.com/t/changing-the-cursor-shape-in-a-popup-menu/106618/1 "2025-05-23T08:45:29Z")

</div>

In a project, we change the cursor from an arrow to a hand for all components that are clickable.  
In this same project, we also use the function 'system.gui.createPopupMenu'.  
Is it possible to change the cursor shape of the items in this popup menu to a hand when the item is enabled?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 23, 2025, 3:19pm UTC](https://forum.inductiveautomation.com/t/changing-the-cursor-shape-in-a-popup-menu/106618/2 "2025-05-23T15:19:07Z")

</div>

The menu object you create with `system.gui.createPopupMenu` will be a [`JPopupMenu`](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/JPopupMenu.html). As a [`MenuElement`](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/MenuElement.html) it will have a [`getSubElements()`](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/MenuElement.html#getSubElements()) method that returns the list of defined sub elements. Each of those, as a JComponent, has a [`setCursor`](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/Component.html#setCursor(java.awt.Cursor)) method. To obtain a cursor, use the static method [`getPredefinedCursor`](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/Cursor.html#getPredefinedCursor(int)) on the `Cursor` class, using one of the defined constants.

---

<div class="post-metadata">

**Author:** ![Henk](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@Henk](https://forum.inductiveautomation.com/u/Henk)\
**Post date:** [May 24, 2025, 1:21pm UTC](https://forum.inductiveautomation.com/t/changing-the-cursor-shape-in-a-popup-menu/106618/3 "2025-05-24T13:21:27Z")

</div>

Could you please create a working example script? It’s all still very new to me.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 25, 2025, 12:05am UTC](https://forum.inductiveautomation.com/t/changing-the-cursor-shape-in-a-popup-menu/106618/4 "2025-05-25T00:05:05Z")

</div>

> [@Henk](#):
>
> Could you please create a working example script?

I can do that:

**Example:**

```python
# Recursively sets the cursor on all the sub components of a popup menu
def setMenuCursor(menu, cursor):
	
	# Set the current menu item's cursor property to the given cursor
	menu.cursor = cursor	
	
	# Iterate through all the menu item's sub componentns, and apply the cursor
	for component in menu.components:
		setMenuCursor(component, cursor)

		# If a submenu is found, process the submenu items as well
		if 'JySubMenu' in component. __class__. __name__ :
			setMenuCursor(component.popupMenu, cursor)

# Simple nested popup example based on documented example # 4:
def sayHello(event):
	print 'Hello'
subMenu01 = [["Click Me 1", "Click Me 2"], [sayHello, sayHello]]
subMenu02 = [["Click Me 3", "Click Me 4"], [sayHello, sayHello]]
subMenu03 = [["Click Me 5", "Click Me 6"], [sayHello, sayHello]]
subMenu04 = [["Click Me 7", "Click Me 8"], [sayHello, sayHello]]
subMenu05 = [["Click Me 9", "Click Me 10"], [sayHello, sayHello]]

# Create a popup menu and change its subcomponents' cursors prior to displaying it
menu = system.gui.createPopupMenu(['Click Me', 'subMenu01', 'subMenu02', 'subMenu03', 'subMenu04', 'subMenu05'], [sayHello, subMenu01, subMenu02, subMenu03, subMenu04, subMenu05])

# get the original cursor, and derive a hand cursor using the original cursor's static HAND_CURSOR field
originalCursor = menu.cursor
newCursor = originalCursor.getPredefinedCursor(originalCursor.HAND_CURSOR)

setMenuCursor(menu, newCursor)
menu.show(event, event.x, event.y)

```

**Result:**

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/6/1601ec477f5410e4aee7be5db9cf33f90a40d6f2.png)

**Edit:** Moved the derived cursor outside of the function, and added it as a variable, to make the function more generic

---

<div class="post-metadata">

**Author:** ![Henk](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@Henk](https://forum.inductiveautomation.com/u/Henk)\
**Post date:** [May 26, 2025, 5:58am UTC](https://forum.inductiveautomation.com/t/changing-the-cursor-shape-in-a-popup-menu/106618/5 "2025-05-26T05:58:56Z")

</div>

Thank you very much for this example.
