🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: jTextArea component - help an old newbee!!!

#1462
From: Paul Furbacher
Date: Fri, 28 Nov 2003 17:42
146 lines
5482 bytes
Algis Kabaila wrote:


> I failed to say that I am currently using Win2K as the platform.  Here is a
> sample of input and output (under the header of "Appended text")
> 
> Thanks for looking at it!

You have given us the code, and some sample
output which doesn't fit your expectations,
but I'm left scratching my head as to what
you actually expect.  What are you trying to
do?  What does successful output look like?

Also, why is it necessary to dump the processed
text back into the same component?  Does it
make sense that the user could process some
text, and then press the button to process the
processed text?  (That's what this design suggests.)
Usually, input is separated from output.  Output
is usually set into a display component which
does not allow editing or processing.

Given that you are moving your Delphi based
code to Java, it might be a suitable moment
to reconsider this conflicting use of an
input area as an output device.  Here's
an alternative:



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SimpleTextEditorExampleFrame
     extends JFrame {

   JScrollPane scroller1 = new JScrollPane();
   JScrollPane scroller2 = new JScrollPane();
   JTextArea jTextArea1 = new JTextArea();
   JTextArea jTextArea2 = new JTextArea();
   JButton processButton = new JButton();
   GridBagLayout gridBagLayout1 = new GridBagLayout();


   public SimpleTextEditorExampleFrame() {
     try {
       jbInit();
     }
     catch (Exception ex) {
       ex.printStackTrace();
     }
   }

   void jbInit() throws Exception {
     this.getContentPane().setLayout(gridBagLayout1);
     processButton.setText("Process");
     processButton.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           processButton_actionPerformed(e);
         }
       });
     jTextArea1.setText("");

     jTextArea2.setEditable(false);
     jTextArea2.setBackground(Color.lightGray);
     jTextArea2.setText("");

     this.addWindowListener(
        new java.awt.event.WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            this_windowClosing(e);
          }
        });
     scroller1.getViewport().add(jTextArea1, null);
     scroller1.setPreferredSize(new Dimension(300, 150));
     scroller2.getViewport().add(jTextArea2, null);
     scroller2.setPreferredSize(new Dimension(300, 150));

     this.getContentPane().add(
       scroller1,
       new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
         GridBagConstraints.NORTHWEST,
         GridBagConstraints.BOTH,
         new Insets(12, 12, 11, 11), 0, 0));
     this.getContentPane().add(
       scroller2,
       new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,
         GridBagConstraints.NORTHWEST,
         GridBagConstraints.BOTH,
         new Insets(0, 12, 0, 11), 0, 0));
     this.getContentPane().add(
       processButton,
       new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
         GridBagConstraints.CENTER,
         GridBagConstraints.NONE,
         new Insets(12, 0, 11, 0), 0, 0));
   }

   public static void main(String[] args) {
     SimpleTextEditorExampleFrame frame =
         new SimpleTextEditorExampleFrame();
     frame.pack();
     frame.setVisible(true);
   }

   void processButton_actionPerformed(ActionEvent e) {
     try {
       jTextArea2.setText(jTextArea1.getText());
       jTextArea2.append("\n\n ----\n");
       jTextArea2.append(
           "Line count: " +
           String.valueOf(jTextArea1.getLineCount()) + "\n");
       jTextArea2.append(
           "Character count: " +
           String.valueOf(jTextArea1.getText().length()) + 
"\n");
       jTextArea2.append("----");
     }
     catch (Exception g) {
       jTextArea2.setText("\n Bad location exception occurred");
     }
   }

   void this_windowClosing(WindowEvent e) {
     System.exit(0);
   }
}


-- 


Paul Furbacher (TeamB)

   Save time, search the archives:
        http://www.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://www.visi.com/~gyles19/fom-serve/cache/1.html

   Finally, please send responses to the newsgroup only.
   That means, do not send email directly to me.
   Thank you.
Technical Details
Message-ID: <3fc78900$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <bq3lia$1tiqfa$1@ID-216608.news.uni-berlin.de> <bq3n98$1ublqa$1@ID-216608.news.uni-berlin.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,663e7dcc14de267d
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2003-11-28 09:58:04 PST
Date: Fri, 28 Nov 2003 12:42:27 -0500
From: Paul Furbacher <pfurbacher@mac.com>
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.5) Gecko/20031013 Thunderbird/0.3
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing
Subject: Re: jTextArea component - help an old newbee!!!
References: <bq3lia$1tiqfa$1@ID-216608.news.uni-berlin.de> <bq3n98$1ublqa$1@ID-216608.news.uni-berlin.de>
In-Reply-To: <bq3n98$1ublqa$1@ID-216608.news.uni-berlin.de>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 68.39.103.120
Message-ID: <3fc78900$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1070041344 68.39.103.120 (28 Nov 2003 09:42:24 -0700)
Lines: 147
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail