Differences between Java notes and jtextfield jtextarea

Source: Internet
Author: User

1. Single line text input box (jtextfield)

In many cases, you may need to enter some text, and then use the text input box. The single-line text input box is implemented by the jtextfield class. Its constructor is as follows:

(1) jtextfield () constructs a new single line text input box.

(2) jtextfield (INT length) constructs a single line text input box with a specified length.

(3) jtextfield (string text) is used to construct a single line text input box that specifies the initial content.

(4) jtextfield (string text, int length) constructs a single line text input box with a specified length and initial content.

(5) jtextfield (document docu, string text, int length) specifies the file storage mode to construct a single line text input box with the specified length and the specified initial content.

2. Multi-line text input box (jtextarea)

The function of the multi-line text input box is the same as that of the single-line text input box, but it can display more text. Because only one line of text can be entered in a single text input box, multiple lines of text input boxes are required when you need to enter and display more text. Multi-line text input boxes are implemented by the jtextarea class. The jtextarea class has four constructor methods:

(1) jtextarea () constructs a new multi-line text input box.

(2) jtextarea (INT row, int column) constructs a multi-line text input box with a specified length and width.

(3) jtextarea (string text) constructs a multi-line text input box that displays the specified text.

(4) jtextarea (string text, int row, int column) constructs a multi-line text input box that specifies the length, width, and text.

(5) jtextarea (document DOC) constructs a multi-line text input box for the specified file storage mode.

(6) jtextarea (document DOC, string text, int row, int column) constructs a multi-line text input box that specifies the file storage mode, length and width, and displays the specified text.

Iii. Example of using the text input component:

 
Import Java. AWT. *; import javax. swing. *; public class textdemo extends jframe {public textdemo () {container contentpane = This. getcontentpane (); jpanel jpanel1 = new jpanel (New gridlayout (3, 1); // create a single row text box object, specify the initial value as "one" jtextfield jtextfield1 = new jtextfield ("one"); // create a password box, specify the default initial value as "password", with "{1} quot; display jpasswordfield jpasswordfield1 = new jpasswordfield ("password"); jpasswordfield. setechochar ('

);

// Create a multi-row text box object with the specified initial value in five rows and five columns

Jtextarea jtextarea1 = new jtextarea ("This Is A jtextarea example! ", 5, 5 );

Jpanel1.add (jtextfield1 );

Jpanel1.add (jpasswordfield1 );

Jpanel1.add (jtextarea1 );

Contentpane. Add (jpanel1 );

This. settitle ("textdemo ");

This. setsize (300,200 );

This. setvisible (true );

}

Public static void main (string ARGs []) {

Textdemo test = new textdemo ();

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.