3 Replies - 936 Views - Last Post: 26 July 2014 - 02:42 PM Rate Topic: -----

#1 Abizzar_D  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 20
  • Joined: 27-August 13

TextArea Arrow question

Posted 20 July 2014 - 04:00 PM

I have a sprite which uses the four arrow keys to move and I have a JTextField which I want to use as a chat. I want the user to be able to use these simultaneously however in order to do that I need to disable the use of left and right arrow keys in the JTextField component how do I do this?
Is This A Good Question/Topic? 0
  • +

Replies To: TextArea Arrow question

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10566
  • View blog
  • Posts: 39,110
  • Joined: 27-December 08

Re: TextArea Arrow question

Posted 22 July 2014 - 10:13 PM

Note that I don't do a ton of work with Swing, so there may be a better way to do this. I would try listening for the KeyEvent in the JTextField and then invoking dispatchEvent() on the appropriate Component containing the main display for your actual game. Dispatch a KeyEvent indicating that the up (or down) arrow was pressed.
Was This Post Helpful? 0
  • +
  • -

#3 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1398
  • View blog
  • Posts: 3,097
  • Joined: 05-April 11

Re: TextArea Arrow question

Posted 26 July 2014 - 11:22 AM

You could add a KeyListener to the component and consume the event as it is coming in
That should remove all default arrow actions for the component :)
You would have to catch the same event higher up in the chain in order to still move the player around before it is consumed

This post has been edited by CasiOo: 26 July 2014 - 11:22 AM

Was This Post Helpful? 0
  • +
  • -

#4 Abizzar_D  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 20
  • Joined: 27-August 13

Re: TextArea Arrow question

Posted 26 July 2014 - 02:42 PM

Well I fixed the problem myself but thanks for your replies!.
Basically this does it.. You remove the indivitual key bindings.
InputMap inputMap = chat_line.getInputMap();
        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,0), "none");
        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,0), "none");


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1