Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / December 2007

Tip: Looking for answers? Try searching our database.

text wrap feature

Thread view: 
bH - 19 Dec 2007 05:48 GMT
Hi All,
I want to have a text wrap feature (wordwrap) when I use this modified
sample of Roedy's
I cannot find a sample of this.

TIA,
bH

import java.awt.*;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
* demonstrate the use of java.awt.TextArea
*
* @author Roedy Green
*/
public final class TestTextAreaX
   {
   // -------------- main() method--------

   /**
    * Debugging harness for a Frame
    *
    * @param args not used.
    */
   public static void main( String args[] )
       {
       final Frame frame = new Frame();

       // The user hitting enter inserts
       //  a \n character into the text.
       final TextArea textarea =
          new TextArea( "this is a TEST" );
       textarea.setBackground( Color.BLACK );
       textarea.setForeground( Color.ORANGE );
       textarea.setFont( new Font( "Dialog",
         Font.BOLD, 15 ) );
       textarea.setEnabled( true );
       textarea.setEditable(true );
       textarea.addTextListener( new TextListener()
       {
       /**
        * Invoked when the value of the text has
        * changed. The code written
        * for this method performs the operations
        * that need to occur when
        * text changes.
        */
       public void textValueChanged( TextEvent e )
           {
           System.out.println(textarea.getText() );
           }
       } );

       frame.add( textarea );

       frame.setSize( 100, 100 );
       frame.addWindowListener( new WindowAdapter()
       {
       /**
        * Handle request to shutdown.
        *
        * @param e event giving details of closing.
        */
       public void windowClosing( WindowEvent e )
           {
           System.exit( 0 );
           }// end WindowClosing
       }// end anonymous class
       );// end addWindowListener line
       frame.validate();
       frame.setVisible( true );
       frame.setSize(162,200);
       }// end main
   }
Andrew Thompson - 19 Dec 2007 08:49 GMT
...
>I want to have a text wrap feature (wordwrap)

Well for pity's sake.  Did you ever consider RTFM on
this matter?

<http://java.sun.com/javase/6/docs/api/javax/swing/JTextArea.html#setWrapStyleWor
d(boolean

)>

Just as a comment, but this is not a help-desk, it is
a good idea to check the JavaDocs (carefully) before
asking for information that is otherwise clearly documented.

Signature

Andrew Thompson
http://www.physci.org/

bH - 30 Dec 2007 06:11 GMT
> ..
>
[quoted text clipped - 14 lines]
>
> Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-setup/200712/1

Continuing the idea of textwrapping

Given this code snippet, I can take a single long line
of more than 80 characters from an IDE. This does partition
the line in appearance

             String str = "string";
             int lenStr = str.length();
             if(lenStr > 70){
               String frontStr = str.substring(0,70);
               String backStr = str.substring(70, lenStr);
               textArea2.append(frontStr+"\r\n");
               textArea2.append(backStr+"\n");
             }
             else
               if (lenStr < 71)
             {
               System.out.println(str);
               textArea2.append(str+"\n");
             }

However, when I copy/paste the 2 broken lines back into the
IDE , and compile it, it will not read it without showing a
an error. I suppose I could use the keyboard to break the line
originally and not automate the task.

If I use the code above, I  want is to make it the broken lines
act so as to read as if I edited it with the keyboard in the
first place.

Your help is appreciated.

bH


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.