Hello all. I've just now noticed a problem with JMEDestkop on the mac that I don't know is new or not.
Running TestJMEDesktop on two macs (both powerpc macs) you cannot move around with the keyboard WASD keys or use the esc key to quit the application.
Putting in a mouse look handler runs fine. Just seems to be a keyboard problem.
I have run it before on my mac but can't remember if I tried moving around so don't know for sure if this is a new bug or not.
The camera input handler in TestJMEDesktop is disabled while some component is focused. Clicking in the scene or on the desktop (not on any component) should unfocus it to let you move around. This was not working on Mac dependably - are you facing this problem?
Ah - yes that was the problem. Commenting out the jmeDesktop.getFocusOwner() in the update works.
Thanks.
Sorry tested on the pc by mistake.
Commenting out the jmeDesktop.getFocusOwner in the update doesn’t fix it for the mac.
It’s like something is eating all the keyboard entries when the desktop doesn’t have focus.
I can click on any text field component and type fine and clicking off the component the cursor goes away. But the lookHandler never seems to get the keyboard events. Can’t even use the escape key to quit.
Make sure the input handler gets enabled. Then JMEDesktop should not have the chance to have any events consumed.
Make sure the input handler gets enabled. Then JMEDesktop should not have the chance to have any events consumed.
I think I'm doing that.
Here is a cleaned up and simplified version you can copy and paste.
On the mac with this code the mouselook works fine but no keyboard input works.
No wired mode with "t", normals with "n", quiting with "esc", or the WASD keys.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.jme.image.Texture;
import com.jme.input.*;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.*;
import com.jme.scene.shape.Box;
import com.jme.scene.state.*;
import com.jme.util.TextureManager;
import com.jmex.awt.swingui.JMEDesktop;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
public class MacGuiProblem extends SimpleGame {
private JMEDesktop jmeDesktop;
private Node desktopNode;
public static void main(String[] args) {
MacGuiProblem app = new MacGuiProblem();
app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
app.start();
}
public void simpleInitGame() {
input = new InputHandler();
FirstPersonHandler firstPersonHandler = new FirstPersonHandler(cam,50,1);
firstPersonHandler.setEnabled(true);
input.addToAttachedHandlers(firstPersonHandler);
setupDesktop(display.getWidth(),display.getHeight(),input);
display.getRenderer().setBackgroundColor(ColorRGBA.blue);
create3DStuff();
}
public void setupDesktop(int width, int height, InputHandler input) {
jmeDesktop = new JMEDesktop("test internalFrame");
jmeDesktop.setup(width,height,false,input);
jmeDesktop.setLightCombineMode(LightState.OFF);
jmeDesktop.getJDesktop().setBackground(new Color(1,1,1,0.0f));
desktopNode = new Node("desktop node");
desktopNode.attachChild(jmeDesktop);
desktopNode.setCullMode(Spatial.CULL_NEVER);
rootNode.attachChild(desktopNode);
createBoxBorder();
perspective();
createSwingStuff();
}
private void create3DStuff() {
final Vector3f axis = new Vector3f(1,1,0.5f).normalizeLocal();
final Box box = new Box("box",new Vector3f(-5,-5,-5),new Vector3f(5,5,5));
box.setModelBound(new BoundingBox());
box.updateModelBound();
box.getLocalTranslation().set(0,0,-10);
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
ts.setTexture(TextureManager.loadTexture(MacGuiProblem.class.getClassLoader()
.getResource("jmetest/data/images/Monkey.jpg"),
Texture.MM_LINEAR,Texture.FM_LINEAR));
box.setRenderState(ts);
box.addController(new Controller() {
private static final long serialVersionUID = 1L;
public void update(float time) {
box.getLocalRotation().fromAngleNormalAxis(timer.getTimeInSeconds(),axis);
}
});
rootNode.attachChild(box);
}
private void createBoxBorder() {
float borderSize = 10;
float halfBorderSize = borderSize /2 ;
int halfDesktopWidth = jmeDesktop.getJDesktop().getWidth()/2;
int halfDesktopHeight = jmeDesktop.getJDesktop().getHeight()/2;
Box top = new Box("top border",new Vector3f(),halfDesktopWidth+halfBorderSize,
halfBorderSize,halfBorderSize);
top.getLocalTranslation().set(0,-halfDesktopHeight,0);
top.setModelBound(new BoundingBox());
top.updateModelBound();
desktopNode.attachChild(top);
Box bottom = new Box("bottom border",new Vector3f(),halfDesktopWidth+halfBorderSize,
halfBorderSize,halfBorderSize);
bottom.getLocalTranslation().set(0,halfDesktopHeight,0);
bottom.setModelBound(new BoundingBox());
bottom.updateModelBound();
desktopNode.attachChild(bottom);
Box left = new Box("left border",new Vector3f(),halfBorderSize,
halfDesktopHeight+halfBorderSize,halfBorderSize);
left.getLocalTranslation().set(-halfDesktopWidth,0,0);
left.setModelBound(new BoundingBox());
left.updateModelBound();
desktopNode.attachChild(left);
Box right = new Box("right border",new Vector3f(),halfBorderSize,
halfDesktopHeight+halfBorderSize,halfBorderSize);
right.getLocalTranslation().set(halfDesktopWidth,0,0);
right.setModelBound(new BoundingBox());
right.updateModelBound();
desktopNode.attachChild(right);
}
private void perspective() {
desktopNode.getLocalRotation().fromAngleNormalAxis(-0.7f,new Vector3f(1,0,0));
desktopNode.setLocalScale(24f/jmeDesktop.getJDesktop().getWidth());
desktopNode.getLocalTranslation().set(0,0,0);
desktopNode.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
desktopNode.setCullMode(Spatial.CULL_NEVER);
}
private void createSwingStuff() {
final JDesktopPane desktopPane = jmeDesktop.getJDesktop();
desktopPane.removeAll();
createSwingInternalFrame(desktopPane,"My Frame 1",10,150);
desktopPane.repaint();
desktopPane.revalidate();
}
private void createSwingInternalFrame(final JDesktopPane desktopPane, final String title, int x, int y) {
final JInternalFrame internalFrame = new JInternalFrame(title);
if(title == null) {
internalFrame.putClientProperty("JinternalFrame.isPalette",Boolean.TRUE);
}
internalFrame.setLocation(x,y);
internalFrame.setResizable(true);
internalFrame.getContentPane().setLayout(new FlowLayout());
JButton button1 = new JButton("button in "+title);
button1.setMnemonic('u');
internalFrame.getContentPane().add(button1);
internalFrame.getContentPane().add(new JButton("<html><i>test</i><big>2</big></html>"));
internalFrame.setVisible(true);
internalFrame.pack();
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("clicked");
}
});
final JTextField textField = new JTextField("type in here");
internalFrame.getContentPane().add(textField);
internalFrame.pack();
desktopPane.add(internalFrame);
}
protected void cleanup() {
if(jmeDesktop!=null) {
jmeDesktop.dispose();
}
super.cleanup();
}
}
ESC, n… are not working due to
input = new InputHandler();
WASD should work. Try without a JMEDesktop - it most probably won't work either. Probably there still is another setup problem.
I've been able to strip the code down to remove some red herrings I think.
package jmetests;
import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.*;
import com.jme.scene.shape.Box;
import com.jme.scene.state.*;
import com.jme.util.TextureManager;
import com.jmex.awt.swingui.JMEDesktop;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
public class MacGuiProblem2 extends SimpleGame {
JMEDesktop jmeDesktop;
public static void main(String[] args) {
MacGuiProblem2 app = new MacGuiProblem2();
app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
app.start();
}
public void simpleInitGame() {
jmeDesktop = new JMEDesktop("test internalFrame");
jmeDesktop.setup(display.getWidth(),display.getHeight(),false,null);
display.getRenderer().setBackgroundColor(ColorRGBA.blue);
create3DStuff();
}
private void create3DStuff() {
final Vector3f axis = new Vector3f(1,1,0.5f).normalizeLocal();
final Box box = new Box("box",new Vector3f(-5,-5,-5),new Vector3f(5,5,5));
box.setModelBound(new BoundingBox());
box.updateModelBound();
box.getLocalTranslation().set(0,0,-10);
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
ts.setTexture(TextureManager.loadTexture(MacGuiProblem.class.getClassLoader()
.getResource("jmetest/data/images/Monkey.jpg"),
Texture.MM_LINEAR,Texture.FM_LINEAR));
box.setRenderState(ts);
box.addController(new Controller() {
private static final long serialVersionUID = 1L;
public void update(float time) {
box.getLocalRotation().fromAngleNormalAxis(timer.getTimeInSeconds(),axis);
}
});
rootNode.attachChild(box);
}
protected void cleanup() {
if(jmeDesktop!=null) {
jmeDesktop.dispose();
}
super.cleanup();
}
}
The only way to get keyboard control on the mac is to comment out both
jmeDesktop = new JMEDesktop("test internalFrame");
jmeDesktop.setup(display.getWidth(),display.getHeight(),false,input);
If you only comment out the setup the keyboard still does not work - you can't even create the thing.
uhu, this can only mean the awt frame is stealing focus. Are you sure your jME app is really focused?
How do I make sure it's focused? input.setEnabled(true)?
I've tried doing that before and after creating the jmeDesktop and nothing changes.
no, I mean the application focus - switch to another app and back, for example.
Cool. Doing:
public void simpleInitGame() {
jmeDesktop = new JMEDesktop("test internalFrame");
jmeDesktop.setup(display.getWidth(),display.getHeight(),false,input);
display.getRenderer().setBackgroundColor(ColorRGBA.blue);
((FirstPersonHandler)input).getMouseLookHandler().setEnabled(false);
MouseInput.get().setCursorVisible(false);
create3DStuff();
}
let's you click off the application and than back, after which all keyboard commands start working.
I didn't think this was the problem because mouse look was always working.
Now the question becomes: is there code to force the application to have focus when you start it up? It's going to become slightly annoying to alt-tab or click out of the application and than back just to get the keyboard to work correctly. Full-screen mode has the same problem.
Update: after going back to the TestJMEDesktop demo, clicking off the application and than back does give keyboard focus back. However, clicking on any swing component again steals the keyboard focus and you're forced to refocus the application again.
I did not find a method for it, yet, no.
I ran the JMEDesktop test on Mac 10.5 with the latest snapshot build r4093, and had a similar problem as identified earlier in this thread; no exception is printed to the console, but I am unable to navigate using keyboard or mouse (though other sample apps handle mouse and keyboard properly). Has anyone else reproduced this problem, or identified workarounds for it?
Thanks,
Sam Reid
No, this has never been completely implemented for the mac. I don't remember what the problem was, but noone has really looked at it since.
I've posted a patch for many of the Mac related problems in this thread:
http://www.jmonkeyengine.com/jmeforum/index.php?topic=11200.msg84466#msg84466
Sam Reid
Hi all,
I have a problem when I alt+tab out and in again to my JMEGame.
If I’m displaying an internalframe inside JMEDesktop (the login window in my case) I can write into the JTextFields but when I alt+tab out and in again I can’t write into the TextFields anymore. I can focus the JTextField by clicking on them, but no characters appear if I type.
I see that it also happens in the TestJMEDesktop.
Do you know what’s wrong here? I type and alt+tab several times in my game , please help!