🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Swap Enter and Ctrl-Enter for JTextArea

#541
From: Tony
Date: Thu, 16 Jun 2005 05:55
40 lines
2350 bytes
>
> 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: <42b1144d$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed2.easynews.com!easynews.com!easynews!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <42b0f990$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
From: "Tony" <aoganesi_a^t_yahoo_._com>
Newsgroups: borland.public.jbuilder.java.swing
References: <42b0f990$1@newsgroups.borland.com>
Subject: Re: Swap Enter and Ctrl-Enter for JTextArea
Date: Wed, 15 Jun 2005 22:55:25 -0700
Lines: 42
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
NNTP-Posting-Host: 69.33.38.98
Message-ID: <42b1144d$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1118901325 69.33.38.98 (15 Jun 2005 22:55:25 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed2.easynews.com!easynews.com!easynews!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail