Java JTextArea Example

Java JTextArea Example

Java JTextArea Example
JTextArea is a swing component that displays multiple lines text.JTextField is same as JTextArea only that it displays single line text.

How to Declare JTextArea class

[public class JTextArea extends JTextComponent]

JTextArea used constructors.

  • JTextArea()-create a empty JTextArea with no text.
  • JTextArea(String s)-creates a JTextArea with a text inside it.
  • JTextArea(int row,int col)-creates a JTextArea with specified number of rows and columns.
  • JTextArea(String s,int row,int col)-creates a JTextArea with a initial text and specified number of columns and rows.

JTextArea common methods.

  • void setRows(int rows)-used to set number of rows in a JTextArea.
  • void setColumns(int col)-used to set number of columns.
  • void setFont(Font f)-used to set Font size.
  • void  insert(String s,int position)-inserts a text in a specified position.
  • void append(String s)-used to append text at the end.

Java JTextArea Example

[
import javax.swing.JTextArea;
import javax.swing.JFrame;

public class TextArea extends JFrame{
    public TextArea()
    {
        super("JTextArea Example");
        JTextArea area=new JTextArea();
        area.setBounds(30, 30, 200, 200);
        add(area);
        setSize(300,300);
        setLayout(null);
        setVisible(true);


    }
    public static void main(String args[])
    {
        new TextArea();
    }
}
]

Java JTextArea Example with ActionListener

[
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JLabel;
import javax.swing.JFrame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class JTextAreaExample  implements ActionListener{

    JLabel label1,label2;
    JButton button;
    JTextArea area;
    public JTextAreaExample()
    {
        JFrame frame=new JFrame("JTextArea Example");
        label1=new JLabel();
        label1.setBounds(50,25,100,30);


        label2=new JLabel();
        label2.setBounds(160,25,100,30);
        area=new JTextArea();
        area.setBounds(20,75,250,200);
        button=new JButton("Count Words");
        button.setBounds(100,300,120,30);
        button.addActionListener(this);
        frame.add(label1);
        frame.add(label2);
        frame.add(area);
        frame.add(button);
        frame.setSize(450,450);
        frame.setLayout(null);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

    }
    public void actionPerformed(ActionEvent event)
    {
        String text=area.getText();
        String words[]=text.split("\\s");
        label1.setText("Words: "+words.length);
        label2.setText("Characters: "+text.length());
    }
    public static void main(String args[])
    {
        new JTextAreaExample();
    }
}
]

Output

Java JTextArea Example with ActionListener


See also:

COMMENTS

Name

android android Apps android emulators antivirus blogger bluestack Break Statement in Java constructors download downloader drivers emulators java java control statements java do-while loop java for loop java infinitive do-while loop java system methods java tutorials Java While Loop java.awt java.swing javalookandfeel javascript JButton JCheckBox JColorChooser JComboBox JDialog JFileChooser JFrame JLayeredPane JList JMenuBar joomla JOptionPane JPanel JPasswordField JPopupMenu JProgressBar JRadioButton JScrollBar JSlider JSpinner JTabbedPane JTable JTextArea JTextField JToolBar mysql php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
false
ltr
item
Java Codes: Java JTextArea Example
Java JTextArea Example
Java JTextArea Example
https://4.bp.blogspot.com/-HErthEA8rug/WLxabcRKQpI/AAAAAAAAHCg/UPn0Xyuy1mUqC35GttpxuosHf7sh2iDHwCLcB/s200/Java-jtextarea-example-min.PNG
https://4.bp.blogspot.com/-HErthEA8rug/WLxabcRKQpI/AAAAAAAAHCg/UPn0Xyuy1mUqC35GttpxuosHf7sh2iDHwCLcB/s72-c/Java-jtextarea-example-min.PNG
Java Codes
http://www.download-all.net/2017/03/java-jtextarea-example.html
http://www.download-all.net/
http://www.download-all.net/
http://www.download-all.net/2017/03/java-jtextarea-example.html
true
7826648292785071009
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy