Sunday, 22 February 2015

A Tutorial On Simple Text Area

Before using Text area we should know what is it.Sometimes a single line of text input is not enough for a task.To handle these situations Swing includes a multi line editor called TextArea.following are constructors for TextArea.

JTextArea();

JTextArea(int numLines,int numChars);
JTextArea(String str,int numLines,int numChars);
JTextArea(String str,int numLines,int numChars,int sBars);

Here numLines specifies the height in linesand numchars specifies width in characters.we can also specify initial string specified by str. We can also specify scrollbar with it.If you want to add text area in scroll pane then see our tutorial How to add text area in scroll Pane .

CODING:

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

class myjframe1 extends JFrame {
JTextArea textArea = new JTextArea();
public myjframe1()
 {
setTitle("Simple example");
setDefaultCloseOperation(EXIT_ON_CLOSE);    
JTextArea textArea = new JTextArea(10,30);
setLayout(new FlowLayout(FlowLayout.CENTER));
add(textArea);
setSize(300, 200);
setVisible(true);
}
}
class simptext
{
public static void main(String args[])
{
myjframe1 x= new myjframe1();
}
}

OUTPUT:



No comments:

Post a Comment