I’m making a scene editor and I want to use swing controls.
The problem is that the canvas behaves in a way that I don’t understand.
It seems to suck the keyboard events even when disabled. This makes it impossible to use a TextField control for example.
Another thing I don’t understand is that when I switch from my application window to another window and back the controls are useable regardless of canvas state;
Disabling/Enabling canvas is also not working properly.
[java]import com.jme3.app.Application;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeCanvasContext;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
public class TestCanvas {
private static Canvas canvas;
private static Application app;
private static JFrame frame;
private static Container canvasPanel;
private static JTextField textField;
private static JButton enable;
private static JButton disable;
private static void createFrame() {
frame = new JFrame(“test”);
textField = new JTextField();
enable = new JButton(“Enable”);
disable = new JButton(“Disable”);
enable.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
canvas.setEnabled(true);
}
});
disable.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
canvas.setEnabled(false);
}
});
canvasPanel = new JPanel();
canvasPanel.setLayout(new BorderLayout());
frame.getContentPane().add(textField, BorderLayout.NORTH);
frame.getContentPane().add(canvasPanel, BorderLayout.CENTER);
frame.getContentPane().add(enable, BorderLayout.EAST);
frame.getContentPane().add(disable, BorderLayout.WEST);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter(){
@Override
public void windowClosed(WindowEvent e) {
app.stop();
}
});
}
public static void createCanvas() {
AppSettings settings = new AppSettings(true);
settings.setFrequency(60);
settings.setWidth(640);
settings.setHeight(480);
//app.setPauseOnLostFocus(false);
app.setSettings(settings);
app.createCanvas();
JmeCanvasContext context;
context = (JmeCanvasContext) app.getContext();
context.setSystemListener(app);
canvas = context.getCanvas();
canvas.setSize(settings.getWidth(), settings.getHeight());
}
public static void main(String[] args){
app = new Application();
SwingUtilities.invokeLater(new Runnable(){
public void run(){
createFrame();
createCanvas();
canvasPanel.add(canvas, BorderLayout.CENTER);
app.startCanvas();
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}[/java]
Why don’t you extend the SDK where all this is in place already including scene management and actions per object, selection etc.?
i can’t build the sdk, there’s no harness folder in my jmonkey installation and shit.
i’m noob at this stuff.