Page 1 of 1

Setting a wait cursor in the standalone client

Posted: Thu Dec 05, 2019 10:05 pm
by queshaw
I am working on a WorkspaceAccessPluginExtension. The UI consists of a menu and menu item. How can I set a wait cursor?

What I've tried so far:

Code: Select all

private  AtomicReference<JMenuBar> menuRef = new AtomicReference<JMenuBar>(); // Cringe
...
    @Override
    public void applicationStarted(final StandalonePluginWorkspace ws) {
        ws.addMenuBarCustomizer(new MenuBarCustomizer() {
            @Override
            public void customizeMainMenu(JMenuBar menuBar) {
                ...
                menuRef = new AtomicReference(menuBar);
            }
        });
    }
...
       return new AbstractAction("Sync") {
                Cursor cursor = menuRef.get().getCursor();
                 try {
...
                    menuRef.get().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
...
                } finally {
                    menuRef.get().setCursor(cursor);
                }
       } 

Re: Setting a wait cursor in the standalone client

Posted: Fri Dec 06, 2019 12:47 pm
by Radu
Hi,

You should try to set the busy cursor on the entire application main frame, something like:

Code: Select all

    javax.swing.JFrame parentFrame = (JFrame) PluginWorkspaceProvider.getPluginWorkspace().getParentFrame();
    parentFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
otherwise you will only set it on the menu bar area which is probably not what you are after.

Regards,
Radu

Re: Setting a wait cursor in the standalone client

Posted: Tue Dec 10, 2019 2:56 am
by queshaw
Thank you.

This seems to work if I use CROSSHAIR_CURSOR, but the cursor doesn't change if I use WAIT_CURSOR. Do you know why that might be?

Re: Setting a wait cursor in the standalone client

Posted: Tue Dec 10, 2019 11:13 am
by Radu
Hi,

I tested and this works for me:

Code: Select all

      pluginWorkspaceAccess.addMenuBarCustomizer(new MenuBarCustomizer() {
        
        @Override
        public void customizeMainMenu(JMenuBar mainMenu) {
          JMenu custom = new JMenu("ABC");
          custom.add(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));
            }
          });
          mainMenu.add(custom);
        }
      });
    
Regards,
Radu

Re: Setting a wait cursor in the standalone client

Posted: Tue Dec 10, 2019 9:09 pm
by queshaw
Ok. That works. Thanks!