Posted by
rndfax on
Dec 27, 2015; 9:30am
URL: https://forum.jogamp.org/NewtCanvasAWT-key-bindings-tp4035922p4035925.html
Hello!
> Please use JOGL 2.3.2. If you find a bug, we won't be able to help you if you don't use the latest version.
Ok, I'm using it now - downloaded from
http://jogamp.org/deployment/jogamp-current/archive/Sources/ and built it.
> Do you have the same problem if you replace NewtCanvasAWT by java.awt.Canvas?
No, with java.awt.Canvas everything is fine. Below you can see the code for java.awt.Canvas which works.
import com.jogamp.opengl.*;
import com.jogamp.newt.opengl.*;
import com.jogamp.newt.awt.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import static javax.swing.JComponent.*;
class Hz extends Canvas {
public Hz() {
setBackground(Color.BLACK);
}
}
public class Main {
public static void main(String[] args) throws Exception {
GLProfile glprofile = GLProfile.getDefault();
GLCapabilities glcaps = new GLCapabilities(glprofile);
GLWindow win = GLWindow.create(glcaps);
JPanel jPanel1 = new JPanel();
jPanel1.setLayout(new BorderLayout());
jPanel1.add(new Button("north"), BorderLayout.NORTH);
jPanel1.add(new Button("south"), BorderLayout.SOUTH);
jPanel1.add(new Button("east"), BorderLayout.EAST);
jPanel1.add(new Button("west"), BorderLayout.WEST);
// jPanel1.add(new NewtCanvasAWT(win), BorderLayout.CENTER);
jPanel1.add(new Hz(), BorderLayout.CENTER);
JFrame jFrame1 = new JFrame("Swing Parent JFrame");
jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame1.setContentPane(jPanel1);
ActionMap am = jFrame1.getRootPane().getActionMap();
InputMap im = jFrame1.getRootPane().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
im.put(KeyStroke.getKeyStroke('w'), "eraser");
am.put("eraser", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
System.out.println("!!!!!!!!");
}
});
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
jFrame1.setSize(640, 480);
jFrame1.validate();
jFrame1.setVisible(true);
}
});
}
}