Page 1 of 1

Setting the wait cursor in case of pupup menu custom action

Posted: Wed Nov 16, 2022 7:12 pm
by Vince
How can I set a wait cursor in case of custom action inserted to the popup menu ?
What I've tried so far:

Code: Select all

public void customizeAuthorPopUpMenu(JPopupMenu popUp, AuthorAccess authorAccess) {
            AbstractAction custom = new AbstractAction("TEST") {
            
            @Override
            public void actionPerformed(ActionEvent e) {
              javax.swing.JFrame parentFrame = (JFrame) PluginWorkspaceProvider.getPluginWorkspace().getParentFrame();
              parentFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 
              try {
                Thread.sleep(10000);
              } catch (InterruptedException e1) {
                e1.printStackTrace();
              }
              parentFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
            }
          };
          popUp.insert(custom, 0);
        }        
}
Thanks

Re: Setting the wait cursor in case of pupup menu custom action

Posted: Wed Nov 16, 2022 10:14 pm
by Radu
Hi,

The code looks good to me, so when the action is invoked at first it sets the cursor on the main frame to wait_cursor, then the action performs its specific code and then at the end you switch the cursor on the main frame back to the normal cursor.
So doesn't the code work? What's the current behavior you obtain?

Regards,
Radu

Re: Setting the wait cursor in case of pupup menu custom action

Posted: Thu Nov 17, 2022 1:52 pm
by Vince
Hi,

The code does not work.
Cursor does not change at all.

I'm using Oxygen 23

Regards,
Vincent

Re: Setting the wait cursor in case of pupup menu custom action

Posted: Thu Nov 17, 2022 2:23 pm
by Vince
I do some additionnal tests.

When I click on the menu item, if my mouse pointer hovers over the tab, the wait cursor appears
If my mouse pointer is just under the tab, cusrosr does not change.

It's seems that the editing area cursor takes priority over the one I set.

Hope this helps.

Regards,
Vincent

Re: Setting the wait cursor in case of pupup menu custom action

Posted: Fri Nov 18, 2022 9:03 am
by Radu
Hi Vincent,

Indeed the Author panel has its own text I-beam cursor set. And setting a cursor on the parent frame does not impose the same cursor on descendant Swing components.
Maybe you can try to cast this "authorAccess.getEditorAccess().getAuthorComponent()" to a JPanel and set the busy cursor also on it.

Regards,
Radu

Re: Setting the wait cursor in case of pupup menu custom action

Posted: Fri Nov 18, 2022 2:40 pm
by Vince
Great, it works !

Thanks