Newt and JpopUpMenu

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Newt and JpopUpMenu

elect
Hi,

I would like to ask which is the right way to implement a right-click menu

With the old glCanvas, we were using the JpopUpMenu, now with Newt we add it to newtCanvasAWT but it is not working very well, it flickers, it not always appears and the background selection is not there..

Reply | Threaded
Open this post in threaded view
|

Re: Newt and JpopUpMenu

gouessej
Administrator
Hi

Try JPopupMenu.setDefaultLightWeightPopupEnabled(false), call that very early in your program.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Newt and JpopUpMenu

elect
It is funny, because if I run this code

public void popUp() {

        JPopupMenu popupMenu = new JPopupMenu();
       
        popupMenu.add(new JMenuItem("test1"));
        popupMenu.add(new JMenuItem("test2"));
       
        popupMenu.show(EC_GUI.main.getGlViewer().getNewtCanvasAWT(), 10, 10);
       
        popupMenu.setVisible(true);
    }


The popup is working, that is if I move the mouse over a menuItem it gets selected and if I click somewhere else it disappears

But if I run this code from the MouseListener

try{
        int x = me.getX();
        int y = me.getY();
        if (me.getModifiers()==MouseEvent.BUTTON3_MASK)
        {
            EC_GUI.main.hub.popUp(x, y);
        }
        }catch(Throwable ex)
        {
            ex.printStackTrace();
        }


It gets stuck, that is no background selection on items, no disappearing if clicking somewhere else

Often the application doesnt answer anymore, but nothing I do not get any exception on the console output

Why?
Reply | Threaded
Open this post in threaded view
|

Re: Newt and JpopUpMenu

elect
Found the issue

The problem is the thread...

if I run this, no problem

if (me.getModifiers()==MouseEvent.BUTTON3_MASK)
        {
//            EC_GUI.main.hub.popUp(x, y);
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    EC_GUI.main.hub.popUp();
                }
            });
           
        }
Reply | Threaded
Open this post in threaded view
|

Re: Newt and JpopUpMenu

gouessej
Administrator
Thanks for the feedback. Swing components should always be manipulated on Swing event dispatching thread.
Julien Gouesse | Personal blog | Website