Skip to content

Instantly share code, notes, and snippets.

@stacktracer
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stacktracer/0617b091d3d184f0a887 to your computer and use it in GitHub Desktop.
Save stacktracer/0617b091d3d184f0a887 to your computer and use it in GitHub Desktop.
Popup Test with Workaround
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.swing.JFrame;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.event.MouseAdapter;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
public class PopupTest2
{
public static void main( String[] args )
{
GLProfile glProfile = GLProfile.getMaxFixedFunc( true );
GLCapabilities glCapabilities = new GLCapabilities( glProfile );
GLWindow glWindow = GLWindow.create( glCapabilities );
final NewtCanvasAWT glCanvas = new NewtCanvasAWT( glWindow );
// Workaround (step 1 of 2) for https://jogamp.org/bugzilla/show_bug.cgi?id=1127
glWindow.addWindowListener( 0, new WindowAdapter( )
{
public void windowGainedFocus( WindowEvent ev )
{
ev.setConsumed( true );
}
} );
final JFrame frame = new JFrame( "Popup Test" );
frame.getContentPane( ).add( glCanvas );
final JPopupMenu menu = new JPopupMenu( );
menu.setLightWeightPopupEnabled( false );
menu.add( "Menu item 1" );
menu.add( "Menu item 2" );
menu.add( "Menu item 3" );
glWindow.addMouseListener( new MouseAdapter( )
{
public void mousePressed( final MouseEvent ev )
{
SwingUtilities.invokeLater( new Runnable( )
{
public void run( )
{
// Workaround (step 2 of 2) for https://jogamp.org/bugzilla/show_bug.cgi?id=1127
if ( !menu.isVisible( ) )
{
menu.show( glCanvas, ev.getX( ), ev.getY( ) );
}
else
{
menu.setVisible( false );
}
}
} );
}
} );
SwingUtilities.invokeLater( new Runnable( )
{
public void run( )
{
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.setSize( 800, 600 );
frame.setLocationRelativeTo( null );
frame.setVisible( true );
}
} );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment