which works when enter is pressed the output comes, but the focus is not gained to that textarea.
I built the textarea like this:
final JMEDesktop desktop = new JMEDesktop( "desktop", DisplaySystem.getDisplaySystem().getWidth() / 2, DisplaySystem.getDisplaySystem().getHeight() / 4, GTASGame.getInstance().input );
// and attach it to the gui node
this.attachChild( desktop );
SwingUtilities.invokeLater( new Runnable() {
public void run() {
// make it transparent blue
desktop.getJDesktop().setBackground( new Color( 0, 0, 0, 0.0f ) );
infoTextArea = new JTextArea(5,50);
infoTextArea.setBackground(new Color(238,238,238));
infoTextArea.setAutoscrolls(true);
infoTextArea.setEditable(true);
infoTextArea.setFocusable(true);
infoTextArea.setSize(infoTextArea.getPreferredSize());
JScrollPane scrollPane = new JScrollPane(infoTextArea);
scrollPane.setOpaque(false);
scrollPane.setLocation(10,10);
scrollPane.setSize(scrollPane.getPreferredSize());
desktop.getJDesktop().add(scrollPane);
Focus is gained though when i click on the textarea with mouse.
How can I make that component gain focus?
The, IngameHUD.getInstance().desktop.setFocusOwner(IngameHUD.getInstance().infoTextArea), gives me exception:
SEVERE: Exception in game loop
java.lang.IllegalStateException: not in swing thread!
at com.jmex.awt.swingui.JMEDesktop.dispatchEvent(JMEDesktop.java:669)
at com.jmex.awt.swingui.JMEDesktop.setFocusOwner(JMEDesktop.java:891)
at gtas.player.actions.MessageTypingAction.performAction(MessageTypingAction.java:15)
at com.jme.input.ActionTrigger.performAction(ActionTrigger.java:264)
at com.jme.input.ActionTrigger$CommandTrigger.performAction(ActionTrigger.java:291)
at com.jme.input.InputHandler.processTriggers(InputHandler.java:426)
at com.jme.input.InputHandler.update(InputHandler.java:411)
at gtas.PlayerInputHandler.update(PlayerInputHandler.java:41)
at gtas.GTASGame.update(GTASGame.java:189)
at com.jme.app.BaseGame.start(BaseGame.java:84)
at gtas.GTASGameServer$1.run(GTASGameServer.java:36)
Tx for the reply but i tried it, program didnt crash but it didnt have any effect. Maybe anybody can point me to some jmetest for such functionality?
I'm gonna post my code just in case i did something wrong, the action is called when enter is pressed… . Currently I make the mouese visible to navigate to JTextArea.
public class MessageTypingAction extends KeyInputAction{
boolean isTyping=false;
String tempStr;
@Override
public void performAction(InputActionEvent evt) {
SwingUtilities.invokeLater( new Runnable() {
public void run() {
IngameHUD.getInstance().desktop.setFocusOwner(IngameHUD.getInstance().infoTextArea);
tempStr = IngameHUD.getInstance().chatBox.getText();
}
});