🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #542

Re: Swap Enter and Ctrl-Enter for JTextArea

#542
From: John T. Dow
Date: Thu, 16 Jun 2005 14:48
46 lines
2600 bytes
This is what I was missing:  ke.setModifiers(0);

Thanks.

Tony wrote:
>>However, I don't know how to make Ctrl-Enter put an "Enter" into the text, 
>>that is, a hard return.
>>
> 
> 
>  add the following code to the constructor of the small wrapper class
> (e.g. MyTextArea) 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();
>                 }
>                 else if (ke.getKeyCode() == KeyEvent.VK_ENTER
>                           && ke.isControlDown())
>                 {
>                     ke.setKeyCode(KeyEvent.VK_ENTER);
>                     // The following uses a deperecated API,
>                     // it seems that there is not workaround
>                     ke.setModifiers(0);
>                     return;
>                 }
>                 else if (ke.getKeyCode() == KeyEvent.VK_ENTER)
>                 {
>                     ke.consume();
>                     TTextArea.this.transferFocus();
>                 }
>             }
>         });
> 
> 
Technical Details
Message-ID: <42b19123$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <42b0f990$1@newsgroups.borland.com> <42b1144d$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,e83a8bc1bbbfe4c9
X-Google-Attributes: gid111d45,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Thu, 16 Jun 2005 10:48:03 -0400
From: "John T. Dow" <jtdpppoe@earthlink.net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing
Subject: Re: Swap Enter and Ctrl-Enter for JTextArea
References: <42b0f990$1@newsgroups.borland.com> <42b1144d$1@newsgroups.borland.com>
In-Reply-To: <42b1144d$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 151.201.42.212
Message-ID: <42b19123$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1118933283 151.201.42.212 (16 Jun 2005 07:48:03 -0700)
Lines: 47
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail