I'm having trouble with KeyListeners in my SWT application while using JOGL's NewtCanvasSWT.
If I have a org.eclipse.swt.events.KeyListener attached to a SWT Composite and a com.jogamp.newt.event.KeyListener attached to a GLWindow, the SWT Composite never seems to receive keyboard focus. I put together a simple demonstration below. No matter where you click with the mouse, only the NEWT KeyListener will fire. Is this expected behavior? import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.newt.swt.NewtCanvasSWT; public class Application { public static void main( String[] args ) { Display display = new Display( ); Shell shell = new Shell( display ); shell.setSize( 200, 200 ); shell.setLayout( new FillLayout( ) ); Composite background = new Composite( shell, SWT.NONE ); background.setLayout( new FillLayout( ) ); final Composite composite = new Composite( background, SWT.NONE ); // this KeyListener never fires (Composite never seems to receive key focus) composite.addKeyListener( new org.eclipse.swt.events.KeyAdapter( ) { @Override public void keyReleased( org.eclipse.swt.events.KeyEvent e ) { System.out.println( "Composite (SWT): " + e.keyCode ); } } ); GLCapabilities glCapabilities = new GLCapabilities( GLProfile.getMaxFixedFunc( true ) ); GLWindow glWindow = GLWindow.create( glCapabilities ); NewtCanvasSWT glCanvas = new NewtCanvasSWT( background, SWT.NONE, glWindow ); // this is the only KeyListener which fires glWindow.addKeyListener( new com.jogamp.newt.event.KeyAdapter( ) { @Override public void keyReleased( com.jogamp.newt.event.KeyEvent e ) { System.out.println( "Window (NEWT): " + e.getKeyCode( ) ); } } ); shell.open( ); while ( !shell.isDisposed( ) ) { if ( !display.readAndDispatch( ) ) display.sleep( ); } display.dispose( ); } } |
Free forum by Nabble | Edit this page |