Board index » jbuilder » Swap TAB and Ctrl-TAB for JTextArea
Magnus
![]() JBuilder Developer |
Magnus
![]() JBuilder Developer |
Swap TAB and Ctrl-TAB for JTextArea2005-05-16 10:33:01 PM jbuilder0 Hi, I would like to swap the behavior of the TAB function for a JTextArea. I constantly use TAB to go to next focus and always get caught in the text area. I might be bad at finding the simplest thing but I have searched the web, my java books, jbuilder help, ... but can't find any help on this subject. (I found some questions on Google news but no replies). Magnus |
Lori M Olson [TeamB]
![]() Java Developer |
2005-05-16 11:39:35 PM
Re:Swap TAB and Ctrl-TAB for JTextArea
Magnus wrote:
QuoteHi, www.devx.com/tips/Tip/13866 To the insanely complex: forums.java.sun.com/thread.jspa -- Regards, Lori Olson [TeamB] ------------ Save yourself, and everyone else, some time and search the newsgroups and the FAQ-O-Matic before posting your next question. Google Advanced Newsgroup Search www.google.ca/advanced_group_search Other Newsgroup Searches: www.borland.com/newsgroups/ngsearch.html Joi Ellis's FAQ-O-Matic: www.visi.com/~gyles19/fom-serve/cache/1.html |
Magnus
![]() Java Developer |
2005-05-17 03:32:48 AM
Re:Swap TAB and Ctrl-TAB for JTextArea
Thanks Lori,
I will go for the simple: textArea.addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent ke){ if(ke.getKeyCode() == KeyEvent.VK_TAB) { ke.consume(); [nextComponent].requestFocus(); }}}); It seems to work pretty good. I also wanted to implement SHIFT-TAB but couldn't find any KeyEvent.[SHIFT-TAB] so I went to: java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html Now, this example didn't even read tabs... I will investigate later, Thanks again. Lori M Olson [TeamB] wrote: QuoteMagnus wrote: {smallsort} |
John McGrath [TeamB]
![]() Java Developer |
2005-05-19 09:47:10 AM
Re:Swap TAB and Ctrl-TAB for JTextArea
On 5/16/2005 at 3:32:48 PM, Magnus wrote:
QuotetextArea.addKeyListener(new KeyAdapter(){ information on Swing/AWT focus handling, see the trail "How to Use the Focus Subsystem" in the Java Tutorial: java.sun.com/docs/books/tutorial/uiswing/misc/focus.html -- Regards, John McGrath [TeamB] --------------------------------------------------- Before sending me e-mail, please read: www.JPMcGrath.net/newsgroups/e-mail.html |
Magnus
![]() Java Developer |
2005-05-20 10:45:31 PM
Re:Swap TAB and Ctrl-TAB for JTextArea
No. I want to change the behavior of TAB for JTextArea.
When I have a panel with multiple text fields I use TAB to go to the next field. However, as soon as I entered text in a JTextArea I inserted a TAB instead of going to the next field. I can't see why the implementation of TAB behavior should differ for one component like that. In the MS world CTRL-TAB insert a tab and I guess that that is what most user is expecting even for Java developed applications. Thanks for the input on traversal though - that is something I will use in other places. John McGrath [TeamB] wrote: QuoteOn 5/16/2005 at 3:32:48 PM, Magnus wrote: |
John McGrath [TeamB]
![]() Java Developer |
2005-05-23 03:29:45 PM
Re:Swap TAB and Ctrl-TAB for JTextArea
On 5/20/2005 at 10:45:31 AM, Magnus wrote:
QuoteWhen I have a panel with multiple text fields I use TAB to character. QuoteI can't see why the implementation of TAB behavior should differ reasonable compromise. And if you do not like it, you can change it. QuoteIn the MS world CTRL-TAB insert a tab Are you aware of any official MS specification that says that the TAB key should work that way? -- Regards, John McGrath [TeamB] --------------------------------------------------- Before sending me e-mail, please read: www.JPMcGrath.net/newsgroups/e-mail.html |
Magnus
![]() Java Developer |
2005-05-24 09:19:58 PM
Re:Swap TAB and Ctrl-TAB for JTextAreaQuoteThe TAB key is normally a focus traversal key, but the text for a Quote>I can't see why the implementation of TAB behavior should differ though it can be very long)? I don't know what criteria was behind the TAB decision but I would probably stick with consistency (but that is just me). QuoteThe TAB key has been used both for focus traversal and for inserting a TAB QuoteIt does not do that consistently. I have found many Microsoft QuoteAre you aware of any official MS specification that says that the TAB key traverse. |
John McGrath [TeamB]
![]() Java Developer |
2005-05-25 03:57:31 PM
Re:Swap TAB and Ctrl-TAB for JTextArea
On 5/24/2005 at 9:19:58 AM, Magnus wrote:
QuoteNow, why is it that a text entry that can work with more than one row control characters. So to me, it seems inconsistent to allow TABs, but not allow newlines. I also think it is quite rare to actually need to insert TAB characters into a text field. I searched through many applications on my system, and while I found a few that would insert a TAB on Control-TAB, I found none where it actually made sense to do so. So I do not think it makes sense for this to be the default behavior for a JTextField. In the rare cases where it is useful, it can be added. Quote>It does not do that consistently. I have found many Microsoft Remote Desktop, Internet Explorer, Mozilla, Firefox, Thunderbird, Netscape, Opera, XanaNews ...), and all of them have text fields that do not insert a tab character on Ctrl-TAB. I found very few text fields that did exhibit that behavior. Quote>Are you aware of any official MS specification that says that the TAB ad-hoc thing, I am not surprised that it is not. QuoteAll browsers I use (explorer, netscape and firefox) also use tab to That behavior is quite rare, as far as I can see. -- Regards, John McGrath [TeamB] --------------------------------------------------- Before sending me e-mail, please read: www.JPMcGrath.net/newsgroups/e-mail.html |
Tony
![]() Java Developer |
2005-06-02 12:19:55 PM
Re:Swap TAB and Ctrl-TAB for JTextAreaQuoteI will go for the simple: I added the following code to the constructor of the small wrapper class (TTextArea) which extends the JTextArea this.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent ke) { if (ke.getKeyCode() == KeyEvent.VK_TAB && ke.isShiftDown()) { ke.consume(); TTextArea.this.transferFocusBackward(); } else if (ke.getKeyCode() == KeyEvent.VK_TAB) { ke.consume(); TTextArea.this.transferFocus(); } } }); Tony. |