🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
9 messages
9 total messages Started by Magnus Mon, 16 May 2005 14:33
Swap TAB and Ctrl-TAB for JTextArea
#435
Author: Magnus
Date: Mon, 16 May 2005 14:33
11 lines
1239 bytes
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
Re: Swap TAB and Ctrl-TAB for JTextArea
#436
Author: Lori M Olson [TeamB]
Date: Mon, 16 May 2005 15:39
40 lines
2027 bytes
Magnus wrote:
> 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

Doing a Google search on "JTextArea" and "tab" yields many solutions 
from the ridiculously simple:

http://www.devx.com/tips/Tip/13866

To the insanely complex:

http://forums.java.sun.com/thread.jspa?threadID=609727&messageID=3342601

-- 

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
     http://www.google.ca/advanced_group_search
Other Newsgroup Searches:
     http://www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
     http://www.visi.com/~gyles19/fom-serve/cache/1.html
Re: Swap TAB and Ctrl-TAB for JTextArea
#437
Author: Magnus
Date: Mon, 16 May 2005 19:32
49 lines
2355 bytes
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:

http://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:

> Magnus wrote:
> 
>> 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
> 
> 
> Doing a Google search on "JTextArea" and "tab" yields many solutions 
> from the ridiculously simple:
> 
> http://www.devx.com/tips/Tip/13866
> 
> To the insanely complex:
> 
> http://forums.java.sun.com/thread.jspa?threadID=609727&messageID=3342601
> 
Re: Swap TAB and Ctrl-TAB for JTextArea
#440
Author: John McGrath [TeamB]
Date: Thu, 19 May 2005 01:47
25 lines
1736 bytes
On 5/16/2005 at 3:32:48 PM, Magnus wrote:

>      textArea.addKeyListener(new KeyAdapter(){
>        public void keyPressed(KeyEvent ke){
>          if(ke.getKeyCode() == KeyEvent.VK_TAB)
>          {
>            ke.consume();
>            [nextComponent].requestFocus();
>          }}});

It looks like you are just trying to customize the tab order.  If that 
is the case, you should look at java.awt.FocusTraversalPolicy.  For more
information on Swing/AWT focus handling, see the trail "How to Use the
Focus Subsystem" in the Java Tutorial:

    http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: Swap TAB and Ctrl-TAB for JTextArea
#441
Author: Magnus
Date: Fri, 20 May 2005 14:45
33 lines
2430 bytes
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:
> On 5/16/2005 at 3:32:48 PM, Magnus wrote:
> 
> 
>>     textArea.addKeyListener(new KeyAdapter(){
>>       public void keyPressed(KeyEvent ke){
>>         if(ke.getKeyCode() == KeyEvent.VK_TAB)
>>         {
>>           ke.consume();
>>           [nextComponent].requestFocus();
>>         }}});
> 
> 
> It looks like you are just trying to customize the tab order.  If that 
> is the case, you should look at java.awt.FocusTraversalPolicy.  For more
> information on Swing/AWT focus handling, see the trail "How to Use the
> Focus Subsystem" in the Java Tutorial:
> 
>     http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html
> 
Re: Swap TAB and Ctrl-TAB for JTextArea
#442
Author: John McGrath [TeamB]
Date: Mon, 23 May 2005 07:29
33 lines
2239 bytes
On 5/20/2005 at 10:45:31 AM, Magnus wrote:

> 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.

The TAB key is normally a focus traversal key, but the text for a
JTextArea can contain tabs, so JTextArea changes it to insert a tab
character.

> I can't see why the implementation of TAB behavior should differ
> for one component like that. 

The TAB key has been used both for focus traversal and for inserting a TAB
character in text editing applications.  The current behavior seems like a
reasonable compromise.  And if you do not like it, you can change it.

> In the MS world CTRL-TAB insert a tab

It does not do that consistently.  I have found many Microsoft
applications on my system in which that does not work.

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:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: Swap TAB and Ctrl-TAB for JTextArea
#447
Author: Magnus
Date: Tue, 24 May 2005 13:19
33 lines
2435 bytes
> The TAB key is normally a focus traversal key, but the text for a
> JTextArea can contain tabs, so JTextArea changes it to insert a tab
> character.

I noticed.

>>I can't see why the implementation of TAB behavior should differ
>>for one component like that. 

Now, why is it that a text entry that can work with more than one row 
(i.e. text area) insert a TAB but not a text entry for one row (even 
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).

> The TAB key has been used both for focus traversal and for inserting a TAB
> character in text editing applications.  The current behavior seems like a
> reasonable compromise.  And if you do not like it, you can change it.

True and I did.

> It does not do that consistently.  I have found many Microsoft
> applications on my system in which that does not work.

I have found that to but it is not common.

> Are you aware of any official MS specification that says that the TAB key
> should work that way?

No.

All browsers I use (explorer, netscape and firefox) also use tab to 
traverse.
Re: Swap TAB and Ctrl-TAB for JTextArea
#451
Author: John McGrath [TeamB]
Date: Wed, 25 May 2005 07:57
57 lines
3725 bytes
On 5/24/2005 at 9:19:58 AM, Magnus wrote:

> Now, why is it that a text entry that can work with more than one row
> (i.e. text area) insert a TAB but not a text entry for one row (even
> 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).

JTextField allows the user to enter normal characters, while JTextArea
allows the user to insert basic formatting information - in other words,
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.

> > It does not do that consistently.  I have found many Microsoft
> > applications on my system in which that does not work.
> 
> I have found that to but it is not common.

On the applications on my system, it is *extremely* common.  I have looked
at many applications (Microsoft Word, Excel, Outlook, Notepad, FileZilla,
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.

> > Are you aware of any official MS specification that says that the TAB
> > key should work that way?
> 
> No.

If there was one, then I would expect the Swing team to follow it for the
Windows look-and-feel, but not others.  But given that it seems to be an
ad-hoc thing, I am not surprised that it is not.

> All browsers I use (explorer, netscape and firefox) also use tab to
> traverse.

That is what JTextField does also.  I thought you were saying that
JTextField should respond to Ctrl-TAB by inserting a TAB character.
That behavior is quite rare, as far as I can see.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: Swap TAB and Ctrl-TAB for JTextArea
#522
Author: Tony
Date: Thu, 02 Jun 2005 04:19
40 lines
2221 bytes
> 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:
>

I am sure you have figured it out by now, but I was facing the same
problem today and thought it might be useful for someone:

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. 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads