my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes JTextArea size changes on pressing TAB key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextArea size changes on pressing TAB key" Watch "JTextArea size changes on pressing TAB key" New topic
Author

JTextArea size changes on pressing TAB key

Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
When i enter data inside JTextArea, and press TAB key to move to next textfield/ or anything, it doesn't moves. Instead it changes the size of JTextArea each time i press TAB key.
By using "setTabSize(0);" i can stop it from re-sizing the textarea, but how to move to the next textfield?


kunal
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

By default, a JTextArea accepts tabs as characters for its own content. You need to change the key binding (hint: search for those two words) of the tab button.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Adcock
Ranch Hand

Joined: Jan 22, 2011
Posts: 48

Kunal Lakhani wrote:When i enter data inside JTextArea, and press TAB key to move to next textfield/ or anything, it doesn't moves. Instead it changes the size of JTextArea each time i press TAB key.
By using "setTabSize(0);" i can stop it from re-sizing the textarea, but how to move to the next textfield?


I don't know why a JTextArea would resize if you pressed the TAB key.

However, maybe I'm wrong on this, but I'm wondering if you're needing to set the focus to the next textfield.

For the key binding, I think you use the setKeymap() method for that. Or addKeymap().

You might be able to add a KeyListener and simply tell it what you want to do in the method keyTyped().

http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html

I want to say that you might want to use requestFocusInWindow() or something.


Repeal Obamacare.
http://www.dontfundobamacare.com/
http://liberty-amendments.freeforums.net/
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Why fight the default behavior, which is to press <Ctrl>+<Tab> to advance to the next component in the focus cycle? However, if you have to do this the way forward is to set the focus traversal keys for the text area. Look up the method for that, inherited from JComponent.

A JTextArea is usually displayed inside a JScrolPane. Doing that should take care of any resizing issues. Also, what are the wrapping settings on your text area? If you don't understand that question, read the API for methods that contain "wrap"


luck, db
There are no new questions, but there may be new answers.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JTextArea size changes on pressing TAB key
 
Similar Threads
focus is not going to h:selectonemenu on pressing tab key
Disable tab event in JTextArea
Issues with JTextArea as cellEditor of JTable Column.
scrolling a JScrollpane with TAB-Key
Turning off Tab traversal in a JTextArea