![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Sams Teach Yourself Visual J++ 6 in 21 Days
The TextArea ControlThe TextArea control can contain multiple lines of text. Like the TextField control, TextArea controls can be created empty or with an initial string. TextArea controls can be defined with an initial number of rows and columns. The TextArea control inherits most of its functionality from the Text control. ConstructorsThere are five constructors for creating TextArea controls. The first constructor takes no arguments and creates an empty TextArea control. The following example shows how to do this: TextArea text = new TextArea(); The second constructor lets you create a text area and specify the number of rows and columns. It takes two integer arguments, the first one being the number of rows you want, and the second one being the number of columns you want. The following example lets you create a text field of 25 rows and 45 columns: TextArea text = new TextArea( 25, 45 ); The third constructor takes a single argument. That argument is a string. When created, this string will be displayed in the text area. The following example lets you create a text area with a string in it: TextArea text = new TextArea( "Hello there TextArea!" ); The fourth constructor takes three arguments. The first argument is the string that will be initially placed in the text area. The second argument is the number of rows you want, and the third argument is the number of columns you want the text area to have. The next example shows how to create a TextArea object with a string, 25 rows and 45 columns: TextArea text = new TextArea( "Hello there TextArea!", 25, 45 ); The fifth and final constructor is almost identical to the preceding one we discussed, except that it adds a fourth argument that determines how the text areas scrollbars are managed. Table 7.1 shows the available values. Following is an example of the final constructor: TextArea text = new TextArea( "Hello there TextArea!", 25, 45, TextArea.SCROLLBARS_NONE );
EventsTextAreas do not generate action events. They do, however, generate keyboard, focus, and text events. These events are handled exactly in the same way as TextField events. The Label ControlThe most basic user interface control is the Label. The Label is a text string that is usually used to indicate the name of other user-interface components. Label components can be assigned an arbitrary text string and alignment attribute. After a label has been created, the text string and alignment can be queried and modified. ConstructorsThree constructors are available when you create Label controls. The first constructor takes no arguments. The next example shows how to create a label using this constructor: Label label = new Label(); Normally, though, when you create a label, you tell it what text to use. The second label constructor takes a single argument, which is a string. This is the string that will be displayed in the label. The next example shows how to create a label with the text Hello Label: Label label = new Label( "Hello Label" ); The last way to create a Label control is with a constructor that takes two arguments. The first argument is a string that determines the text that will be in the label, and the second argument is the alignment. Three alignment types are available: label.LEFT, label.CENTER, and label.RIGHT. The following example shows how to create a label with the text Hello Label and an alignment of LEFT: Label label = new Label( "Hello Label", Label.LEFT );
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |