Results 1 to 6 of 6

Thread: JTextArea class of java

  1. #1
    Join Date
    Dec 2009
    Posts
    38

    JTextArea class of java

    Hello friends,

    I have to discuss one of my query which is related to the java programming. I am not getting how to use the JTextArea class of java. I don't have sound knowledge about advanced java. I also want to know method as well as the constructors of this class. If you know anything about JTextArea class of java, then please try to share it with me. I would greatly appreciate your any help over this issue.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: JTextArea class of java

    Hi,

    The JTextArea class of java internally handles scrolling. JTextArea is different in that it doesn't manage scrolling, but implements the swing Scrollable interface. This allows it to be placed inside a JScrollPane if scrolling behavior is desired, and used directly if scrolling is not desired. The java.awt.TextArea has the ability to do line wrapping. This was controlled by the horizontal scrolling policy. Since scrolling is not done by JTextArea directly, backward compatibility must be provided another way.

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: JTextArea class of java

    Hi, Please refer following example of JTextArea class with it's methods:
    Code:
    import javax.swing.JTextArea;
    
    public class JTextAreaTestDm {
      public static void main(String[] args) {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame FP = new JFrame("JTextArea Test");
        FP.setLayout(new FlowLayout());
        FP.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        String text = "A JTextArea object represents a multiline area for displaying text. "
            + "You can also put your JTextArea in a JScrollPane to make it scrollable.";
        JTextArea textAreal = new JTextArea(text, 5, 10);
        textAreal.setPreferredSize(new Dimension(100, 100));
        JTextArea textArea2 = new JTextArea(text, 5, 10);
        textArea2.setPreferredSize(new Dimension(100, 100));
        JScrollPane scrollPane = new JScrollPane(textArea2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        textAreal.setLineWrap(true);
        FP.add(textAreal);
        FP.add(scrollPane);
        FP.pack();
        FP.setVisible(true);
      }
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: JTextArea class of java

    To make use of JTextArea class,you should be aware about it's constructors. See following some constructors of JTextArea class:
    • JTextArea(String txt, int rs, int cl)
    • JTextArea(String txt)
    • JTextArea(int rs, int cl)
    • JTextArea(Document dc, String txt, int rs, int cl)
    • JTextArea(Document dc)
    • JTextArea()

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    Re: JTextArea class of java

    Following java example coded to Set font for to JTextArea class. Try to copy this code and then run, then see it's output:
    Code:
    import javax.swing.JTextArea;
    
    public class JTextSample extends JFrame {
    
      String davidMessage = "Put device message here";
    
      public JTextSample() {
        GraphicsEnvironment.getLocalGraphicsEnvironment();
        JTextArea textAreaS = new JTextArea(davidMessage);
        textAreaS.setFont(new Font("LucidaSans", Font.PLAIN, 50));
        this.getContentPane().add(textArea);
        textAreaS.setVisible(true);
      }
    
      public static void main(String[] args) {
        JFrame frame02 = new JTextAreaI18N();
        frame02.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        frame02.pack();
        frame02.setVisible(true);
      }
    }

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: JTextArea class of java

    Hello friend,

    To work JTextArea class, you need to use different methods of JTextArea class. Below I have mentioned some methods with their parameters:
    1. setWrapStyleWord(boolean wrd)
    2. setTabSize(int sizeofTab)
    3. setLineWrap(boolean wrp)
    4. setColumns(int cls)
    5. replaceRange(String strg, int st, int end)
    6. getScrollableUnitIncrement(Rectangle eRect, int or, int direction)

Similar Threads

  1. Converting java class to java bean class
    By Ucchal in forum Software Development
    Replies: 6
    Last Post: 09-08-2010, 10:24 AM
  2. JList class of java
    By Owen Fernandes in forum Software Development
    Replies: 5
    Last Post: 17-02-2010, 08:19 AM
  3. JPanel class of java
    By Ram Bharose in forum Software Development
    Replies: 4
    Last Post: 16-02-2010, 11:01 AM
  4. JViewport class of java
    By Khan Baba in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 11:55 AM
  5. Java Programming Language Basics: Reflection Basics and Class Class
    By mayuri_gunjan in forum Guides & Tutorials
    Replies: 6
    Last Post: 29-08-2005, 12:04 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,061,559.59694 seconds with 17 queries